-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrng.java
More file actions
64 lines (46 loc) · 1.41 KB
/
rng.java
File metadata and controls
64 lines (46 loc) · 1.41 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
//Magnan Sylla CMSC 203
import java.util.Scanner;
import java.util.Random;
public class rng{
public static void main (String [] args) {
Random rng = new Random();
int randNum = rng.nextInt(101);
boolean correctNum = false;
int lowGuess=1;
int i =0;
String restart;
int highGuess = 100;
System.out.println("WELCOME");
System.out.println("Please enter your first guess");
Scanner kbr= new Scanner (System.in);
int guessNum = kbr.nextInt();
do {
i+=1;
System.out.println("Number of guesses is " + i);
if (guessNum < randNum){
System.out.println("Your guess is too low");
lowGuess=guessNum;
System.out.println("Enter your next guess between "+ lowGuess+" and " + highGuess );
guessNum=kbr.nextInt();
}
else if (guessNum > randNum){
System.out.println("Your guess is too high");
highGuess=guessNum;
System.out.println("Enter your next guess between "+ lowGuess + " and " + highGuess );
guessNum=kbr.nextInt();
}
else {
System.out.println("Congratulations, you guessed correctly");
System.out.println("Try again? (yes or no)" );
Scanner kbr1= new Scanner(System.in);
restart=kbr1.next();
if (restart =="yes")
guessNum=0;
System.out.println("Please enter your first guess");
guessNum = kbr.nextInt();
correctNum=true;
}
} while (!correctNum);
System.exit(0);
}
}