From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch10;
02
03 importimport means to make the classes and/or packages available in this program java.util.Scanner;
04
05 /**
06 * Prompt user forfor is a looping structure for repeatedly executing a block of code two integers. Print the sum of the two integers.
07 * Program then halts.
08 */
09 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects AddTwoNumbers {open braces start code blocks and must be matched with a close brace
10 /**
11 * The mainThe main method is the place where applications begin executing. program. Prompt user forfor is a looping structure for repeatedly executing a block of code two integers and add them
12 * together. DOES NOT WORK AS EXPECTED!this is the not operator, which changes true to false and false to true
13 *
14 * @paramnull args command-line arguments; ignored by thisthis means the current object (the implicit parameter) program
15 */
16 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args) {open braces start code blocks and must be matched with a close brace
17 System.out.println("AddTwoNumbers:");
18 Scanner keyboard =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(System.in);
19
20 System.out.print("Number: ");
21 intint is the type for whole numbers and it is short for integer first =this assignment operator makes the left side equal to the right side keyboard.nextInt();
22
23 System.out.print("Number: ");
24 intint is the type for whole numbers and it is short for integer second =this assignment operator makes the left side equal to the right side keyboard.nextInt();
25
26 System.out.println("Sum of " +adds two numbers together or concatenates Strings together first +adds two numbers together or concatenates Strings together " + " +adds two numbers together or concatenates Strings together second +adds two numbers together or concatenates Strings together " = " +adds two numbers together or concatenates Strings together
27 first +adds two numbers together or concatenates Strings together second);
28 }close braces end code blocks and must match an earlier open brace
29 }close braces end code blocks and must match an earlier open brace
30
31 //Uploaded on Mon Mar 29 21:41:16 EDT 2010
|
Download/View scg/ch10/AddTwoNumbers.java