forked from Midway91/HactoberFest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
No_Guessing
33 lines (33 loc) · 1.12 KB
/
No_Guessing
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
import java.util.*;
public class number_guessing_game
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String play="yes";
System.out.println("Welcome to the number guessing game :))");
while(play.equals("yes"))
{
Random r=new Random();
int num=r.nextInt(100);
int gues=-1;
int tries=0;
while(gues!=num)
{
System.out.println("Guess a number between 1 to 100 -------");
gues=sc.nextInt();
tries++;
if(gues==num)
{
System.out.println("Woww!! You guessed the correct number in "+tries+" guesses!!");
System.out.println("Want to play again?? Yes or No :- ");
play=sc.next().toLowerCase();
}
else if(gues>num)
System.out.println("Your guess is too High!! Try Again :||");
else
System.out.println("Your guess is too Low!! Try Again :|| ");
}
}
}
}