-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlFlowExercises.java
More file actions
87 lines (72 loc) · 2.48 KB
/
ControlFlowExercises.java
File metadata and controls
87 lines (72 loc) · 2.48 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
import java.util.Scanner;
public class ControlFlowExercises {
public static void main(String[] args) {
int i = 5;
long x = 2;
Scanner input = new Scanner(System.in);
while (i <= 15) {
System.out.println(i);
i++;
}
// Square Root
do {
System.out.println(x);
x *= x;
} while (x <= 1000000);
// FizzBuzz
for (int j = 1; j <= 100; j++) {
if ((j % 3 == 0) && (j % 5 == 0)) {
System.out.println("FizzBuzz");
} else if (j % 3 == 0) {
System.out.println("Fizz");
} else if (j % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(j);
}
}
// Table of Powers
while (true) {
System.out.println("What number would you like to go up to?");
int number = input.nextInt();
input.nextLine();
System.out.println("number | squared | cubed\n" +
"------ | ------- | -----");
for (int j = 1; j <= number; j++) {
System.out.printf("%-7s| ", j);
System.out.printf("%-8s| ", (j * j));
System.out.printf("%-5s", (j * j * j));
System.out.println();
}
System.out.println("Do you want to continue? y/n");
String option = input.nextLine();
if (!option.equalsIgnoreCase("y")) {
System.out.println("Ok, good bye");
break;
}
}
// Grades
while (true) {
System.out.println("Give me the grade");
int grade = input.nextInt();
input.nextLine();
if (grade <= 100 && grade >= 88) {
System.out.println("A");
} else if (grade <= 87 && grade >= 80) {
System.out.println("B");
} else if (grade <= 79 && grade >= 67) {
System.out.println("C");
} else if (grade <= 66 && grade >= 60) {
System.out.println("D");
} else if (grade <= 59) {
System.out.println("F");
}
System.out.println("Do you want to continue? y/n");
String option = input.nextLine();
if (!option.equalsIgnoreCase("y")) {
System.out.println("Ok, good bye");
break;
}
}
}
}