Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Feb 03

Chapter 2: doubles, Scanner, printf
  • Loading branch information...
commit d80e7f658ee7f87b2831b815a82c4e2b7aa50876 1 parent b2a6fee
bcc32 authored
Showing with 59 additions and 0 deletions.
  1. +21 −0 c2f7a.java
  2. +38 −0 c2n5.java
View
21 c2f7a.java
@@ -0,0 +1,21 @@
+// Aaron Zeng 20120203
+
+import java.util.*;
+
+public class c2f7a
+{
+ public static void main( String[] args )
+ {
+ Scanner input = new Scanner( System.in );
+ double number1, number2, sum;
+
+ System.out.print( "Enter first number: " );
+ number1 = input.nextDouble();
+
+ System.out.print( "Enter second number: " );
+ number2 = input.nextDouble();
+
+ sum = number1 + number2;
+ System.out.printf( "The sum is %f\n", sum );
+ }
+}
View
38 c2n5.java
@@ -0,0 +1,38 @@
+// Aaron Zeng 20120203
+
+import java.util.*;
+
+public class c2n5
+{
+ public static void main( String[] args )
+ {
+ // a) State that a program will calculate the product of three integers.
+ // calculates the product of three integers
+
+ // b) Create a Scanner that reads values from the standard input.
+ Scanner input = new Scanner( System.in );
+ // c) Declare the variables x, y, z, and result to be of type int.
+ int x, y, z, result;
+
+ // d) Prompt the user to enter the first integer.
+ System.out.print( "Enter first integer: " );
+ // e) Read the first integer and store it in the variable x.
+ x = input.nextInt();
+
+ // f) Prompt the user to enter the second integer.
+ System.out.print( "Enter second integer: " );
+ // g) Read the second integer and store it in the variable y.
+ y = input.nextInt();
+
+ // h) Prompt the user to enter the third integer.
+ System.out.print( "Enter third integer: " );
+ // i) Read the third integer and store it in the variable z.
+ z = input.nextInt();
+
+ // j) Compute the product of the three integers and store in result.
+ result = x * y * z;
+
+ // k) Display the message "Product is " followed by the value of result.
+ System.out.printf( "Product is %d\n", result );
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.