From ggc
|
01 packagepackage is used to name the directory or folder a class is in intro;
02 //start auto-imports
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 //end auto-imports
05
06 importimport means to make the classes and/or packages available in this program wiki.Wiki;
07
08 /**
09 * All about my application.
10 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
11 */
12 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 LoopExamples
13 {open braces start code blocks and must be matched with a close brace
14 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)
15 {open braces start code blocks and must be matched with a close brace
16 System.out.print("Enter numerator: ");
17 Scanner scanner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Scanner(Wiki.in);
18 doubledouble is the type for numbers that can contain decimal fractions n=this assignment operator makes the left side equal to the right side0;
19 String number=this assignment operator makes the left side equal to the right sidenullnull is the value used to refer to a non-existant object;
20 booleanboolean is a type that is either true or false success=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
21 whilewhile is a looping structure for executing code repeatedly(success==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
22 {open braces start code blocks and must be matched with a close brace
23 trytry is for executing a code block that may experience exceptions (errors)
24 {open braces start code blocks and must be matched with a close brace
25 number=this assignment operator makes the left side equal to the right sidescanner.next();
26 n=this assignment operator makes the left side equal to the right sideInteger.parseInt(number);
27 System.out.println("Thanks, I see you want to divide "+adds two numbers together or concatenates Strings togethernumber);
28 success=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
29 }close braces end code blocks and must match an earlier open brace
30 catchcatch means to handle an exception that may occur(NumberFormatException e)
31 {open braces start code blocks and must be matched with a close brace
32 //success=false;
33 System.out.println("An error occurred: "+adds two numbers together or concatenates Strings togethere);
34 System.out.println("Sorry, invalid input: "+adds two numbers together or concatenates Strings togethernumber);
35 System.out.println("Please enter only integers like 5, 2, 24.");
36 System.out.print("Enter numerator: ");
37 }close braces end code blocks and must match an earlier open brace
38 }close braces end code blocks and must match an earlier open brace
39 System.out.print("Enter denomenator: ");
40 intint is the type for whole numbers and it is short for integer d=this assignment operator makes the left side equal to the right sidescanner.nextInt();
41 doubledouble is the type for numbers that can contain decimal fractions result=this assignment operator makes the left side equal to the right siden/d;
42 ifif executes the next statement only if the condition in parenthesis evaluates to true(d==this is the comparison operator which evaluates to true if both sides are the same0)
43 {open braces start code blocks and must be matched with a close brace
44 System.out.println("Sorry little brother, you can't divide by zero.");
45 }close braces end code blocks and must match an earlier open brace
46 elseelse is what happens when the if condition is false
47 {open braces start code blocks and must be matched with a close brace
48 System.out.println("When you divide "+adds two numbers together or concatenates Strings togethern+adds two numbers together or concatenates Strings together" by "+adds two numbers together or concatenates Strings togetherd+adds two numbers together or concatenates Strings together" you get "+adds two numbers together or concatenates Strings togetherresult);
49 }close braces end code blocks and must match an earlier open brace
50 }close braces end code blocks and must match an earlier open brace
51 }close braces end code blocks and must match an earlier open brace
|
Download/View intro/LoopExamples.java