-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGuessingGame.java
More file actions
38 lines (26 loc) · 927 Bytes
/
NumberGuessingGame.java
File metadata and controls
38 lines (26 loc) · 927 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
34
35
36
37
38
import org.w3c.dom.ls.LSOutput;
import java.util.Scanner;
import java.util.Random;
public class NumberGuessingGame {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
Random random = new Random();
System.out.println("----NUMBER GUESSING GAME----");
int number=random.nextInt(0,101);
int guess=0,guesses=0;
while(guess!=number){
System.out.print("\nGuess a number (0-100) : ");
guess=scanner.nextInt();
if(guess>number){
System.out.println("Too High!");
}
else if(guess<number){
System.out.println("Too Low!");
}
guesses+=1;
}
System.out.println("\nHURRAH!You got it!");
System.out.printf("You took %d guesses",guesses);
scanner.close();
}
}