forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighLowGame.java
More file actions
33 lines (28 loc) · 795 Bytes
/
HighLowGame.java
File metadata and controls
33 lines (28 loc) · 795 Bytes
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
package Day4;
import java.util.Random;
import javax.swing.JOptionPane;
public class HighLowGame {
public static void main(String[] args) {
Random numGen = new Random();
int randInt = numGen.nextInt(101);
int trys = 1;
int ansAsInt = -1;
while (ansAsInt != randInt) {
String ans = JOptionPane.showInputDialog("pick a number between 1 and 100");
ansAsInt = Integer.parseInt(ans);
System.out.println(ansAsInt);
System.out.println(randInt);
if (ansAsInt > randInt) {
JOptionPane.showMessageDialog(null, "Try again! Lower.");
trys++;
}
if (ansAsInt < randInt) {
JOptionPane.showMessageDialog(null, "Try again! Higher.");
trys++;
}
}
if (ansAsInt == randInt) {
JOptionPane.showMessageDialog(null, "Correct! " +trys +" trys.");
}
}
}