Logout
Sample Class 2 (more to see what's possible...)
ReviewJB.java
/Users/adelaide/Public/Netbeans - All JSR Projects/Review For JB/src/reviewforjbpackage/ReviewJB.java |
1
2 package reviewforjbpackage;
3
4 import java.io.BufferedReader;
5 import java.io.IOException;
6 import java.io.InputStreamReader;
7
8
9
10
11
12
13
14
15 public class ReviewJB {
16 public static void main(String[] args) {
17
18
19 System.out.println(args[0]);
20
21
22
23 System.out.println("Flow of Control");
24 System.out.println("Flow of control refers to the order in which the lines of code are exectuted.");
25 System.out.println("There are three main ways to affect this: conditionals, loops, and methods.");
26
27
28
29 System.out.println("Conditonal Blocks");
30 if((1+3*9) != (2*18)){
31 System.out.println("(1+3*9) does not equal (2*18)");
32 }
33 else{
34 System.out.println("(1+3*9) equals (2*18)");
35 }
36
37
38 int x = 33;
39 int y = 99;
40 if(x == y){
41 System.out.println("x (33) is equal to y (99).");
42 }
43 else{
44 System.out.println("x (33) is not equal to y (99).");
45 }
46
47
48 String a = "hello";
49 String b = "Hello";
50 if(a.equalsIgnoreCase(b)){
51 System.out.println("If we ignore capital and small letters, \"hello\" and \"Hello\" are equal.");
52
53 }
54 else{
55 System.out.println("If we ignore capital and small letters, \"hello\" and \"Hello\" are not equal. ");
56 }
57
58
59 if(a.equals(b)){
60 System.out.println("Normally to a computer \"hello\" and \"Hello\" are not equal.");
61 }
62 else{
63 System.out.println("Normally to a computer \"hello\" and \"Hello\" are not equal.");
64 }
65 System.out.println("");
66
67
68
69 System.out.println("Looping");
70 System.out.println("");
71 int i = 0;
72 while(i < 10){
73 System.out.println("We have not reached 10 yet!!");
74 i+=2;
75 }
76 System.out.println("Made it to 10!!!");
77
78
79
80 System.out.println("printed stuff out");
81 System.out.println("");
82 System.out.print("a");
83 System.out.print("b");
84 System.out.print("c");
85 System.out.println("e");
86 System.out.println("f");
87 System.out.println("g");
88
89
90
91 System.out.println("read stuff in from the console");
92 System.out.println("");
93 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
94 System.out.println("Please enter a word");
95 String theStringReadIn = "not set yet.";
96 try {
97 theStringReadIn = br.readLine();
98 } catch (IOException ex) {
99 System.out.println("This was an error on reading in after \"Please enter a word.\"");
100 }
101 System.out.println("Just to confirm, the word you entered was: " + theStringReadIn);
102
103
104 System.out.println("output more than one thing in one line");
105 System.out.println("");
106 System.out.println("One more demo of this: " + (3*9) + " is the product of 3 and 9.");
107
108
109
110
111 System.out.println("converted a String (word) to a number");
112
113 try{
114 System.out.println("Please enter in one number:");
115 int firstInt = Integer.parseInt(br.readLine());
116 System.out.println("Now enter in another number");
117 int secondInt = Integer.parseInt(br.readLine());
118 System.out.println(firstInt + " x " + secondInt + " = " + firstInt * secondInt);
119
120 }
121 catch(Exception e){
122 System.out.println("This was an error inside the last part of the program");
123 }
124
125 }
126 }