Skip to content

Commit 0ec212d

Browse files
add number guessing game in java
1 parent 0f9c17b commit 0ec212d

File tree

3 files changed

+21
-82
lines changed

3 files changed

+21
-82
lines changed
-3.66 KB
Binary file not shown.

NUMBER GUESSING GAME/NumberGuessingGameGUI.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

numberGuessingGame.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.*;
2+
import java.lang.Math.*;
3+
4+
class NumberGuessingGame{
5+
public static void main(String args[]){
6+
Scanner scan = new Scanner(System.in);
7+
var random = new Random();
8+
int randNum = (random.nextInt(100))+1;
9+
int guess,guessCount=0;
10+
do{
11+
System.out.println("Guess the number: ");
12+
guess = scan.nextInt();
13+
if(guess==randNum){
14+
System.out.println("Your guess is correct!\nYour score is "+(100-guessCount));
15+
}
16+
else
17+
System.out.println(guess>randNum?"Smaller Number ":"Larger Number " + "Try again!");
18+
guessCount++;
19+
}while(guess!=randNum);
20+
}
21+
}

0 commit comments

Comments
 (0)