-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlFlowExercises.java
More file actions
145 lines (126 loc) · 4.52 KB
/
Copy pathControlFlowExercises.java
File metadata and controls
145 lines (126 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.util.Scanner;
public class ControlFlowExercises {
public static void main (String[] arg) {
Scanner myScanner = new Scanner(System.in);
// int i = 5;
//
// while (i <= 15) {
// System.out.printf("%d ", i);
// i++;
// }
//
// System.out.println("-----------------");
// int i = 0;
//
// do {
// i+= 2;
// System.out.println(i);
// }
// while (i <= 100);
// int i = 100;
// do {
// i -= 5;
// System.out.println(i);
// }
// while (i > -10);
// long i = 2;
// do {
// i = i * i;
// System.out.println(i);
// }
// while (i <= 65537L);
// for(int i = 5; i <= 15; i++) {
// System.out.println(i);
// }
//
// for (int i = 2; i <= 100; i++) {
// if(i % 2 == 0) {
// System.out.println(i);
// }
// }
// for (int i = 100; i >= -10; i -= 5) {
// System.out.println(i);
// }
// for(long i = 2; i <= 65536; i *= i){
// System.out.println(i);
// }
//
// for(int i = 0; i <= 100; i++) {
// if(i % 15 == 0) {
// System.out.println("FizzBuzz");
// } else if (i % 5 == 0) {
// System.out.println("Buzz");
// } else if (i % 3 == 0) {
// System.out.println("Fizz");
// } else {
// System.out.println(i);
// }
// }
boolean userContinues = true;
do {
System.out.println("Please enter your max number:");
int number = myScanner.nextInt();
System.out.printf("You entered: %d.", number);
System.out.println();
System.out.printf("Here is your table, up to number: %d", number);
System.out.println();
System.out.println(" number | squared | cubed ");
System.out.println(" ------ | ------- | ----- ");
for (int i = 1; i <= number; i++) {
i = number;
int numberSquared = (int) Math.pow(i, 2);
int numberCubed = (int) Math.pow(i, 3);
System.out.printf("%-7d", i);
System.out.print("|");
System.out.printf("%-8d", numberSquared);
System.out.print("|");
System.out.printf("%-9d", numberCubed);
System.out.println();
}
System.out.print("Would you like to enter another number? Y or N");
String userResponse = myScanner.next();
if(!userResponse.equalsIgnoreCase("y")) {
userContinues = false;
}
} while (userContinues);
// do {
System.out.println("Enter an integer (whole number without digits):");
int grade = myScanner.nextInt();
if (grade <= 59) {
System.out.println("Current grade is a : F");
} else if (grade <= 66) {
if (66 - grade <= 2) {
System.out.println("Current grade is a : D+");
} else if (66 - grade >= 6) {
System.out.println("Current grade is a : D-");
} else
System.out.println("Current grade is a : D");
} else if (grade <= 79) {
if (79 - grade <= 3) {
System.out.println("Current grade is a : C+");
} else if (79 - grade >= 9) {
System.out.println("Current grade is a : C-");
} else
System.out.println("Current grade is a : C");
} else if (grade <= 87) {
if (87 - grade <= 3) {
System.out.println("Current grade is a : B+");
} else if (87 - grade >= 6) {
System.out.println("Current grade is a : B-");
} else
System.out.println("Current grade is a : B");
} else if (grade <= 100) {
if (100 - grade <= 5) {
System.out.println("Current grade is a : A+");
} else if (100 - grade >= 10) {
System.out.println("Current grade is a : A-");
} else
System.out.println("Current grade is a : A");
}
// System.out.print("Continue? (y/n): ");
// userChoice = myScanner.next();
// System.out.println();
// } while (!userChoice.equalsIgnoreCase("n"));
//
}
}