-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testing.java
138 lines (75 loc) · 2.91 KB
/
Testing.java
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
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.util.Random;
public class Testing {
public static void main(String[] args) {
int number1 = 0;
System.out.println("Hello World!");
//my linter doesn't like System.out.println, hmmm
Scanner input1 = new Scanner(System.in);
System.out.println("Please Enter a favorite number");
number1 = input1.nextInt();
System.out.println("You entered: " + number1);
JOptionPane.showMessageDialog(null, "Hello User");
//for loop time
for (int i = 1; i <= 10; i++) {
System.out.println("number: " + i);
//prints number 10 times.
//starts at 1 cause it looks better and doing (i + 1) does not look as good.
} // end for loop
//while loop example, error validation of entering random number
Random random1 = new Random();
int randomNum = random1.nextInt(10) + 1;
int guess = 0;
while (guess != randomNum) {
System.out.println("Guess a number between 1 and 10");
guess = input1.nextInt();
if (guess != randomNum) {
System.out.println("Wrong, try again");
} // end if
} // end while
System.out.println("You guessed it!");
input1.close();
System.out.println("Welcome to Part 2");
//Part 2
String userInput = null;
int number2 = 0;
userInput = JOptionPane.showInputDialog(null, "Please enter a number");
number2 = Integer.parseInt(userInput);
checkOdd(number2);
checkOdd2(number2);
System.out.println(checkOdd3(number2));
//higher or low game
randomNum = random1.nextInt(10) + 1;
guess = 0;
while (guess != randomNum) {
System.out.println("Guess a number between 1 and 10");
guess = input1.nextInt();
if (guess > randomNum)
System.out.println("Too high, try again");
else if (guess < randomNum)
System.out.println("Too low, try again");
else
System.out.println("You guessed it!");
} // end if
} //main end
private static void checkOdd(int number2) {
if (number2 % 2 == 0) {
System.out.println("The number is even");
} else {
System.out.println("The number is odd");
} // end if
}
private static String checkOdd2(int number2) {
String answer = null;
if (number2 % 2 == 0) {
answer = "The number is even";
} else {
answer = "The number is odd";
} // end if
return answer;
}
private static boolean checkOdd3(int number2) {
return (number2 % 2 == 0);
}
} // end class