-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbergame.java
More file actions
50 lines (39 loc) · 1.2 KB
/
numbergame.java
File metadata and controls
50 lines (39 loc) · 1.2 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
import java.util.Scanner;
public class numbergame
{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a=(int)(Math.random()*101);
System.out.println("Welcome to the Number game..");
int maxattempts=5;
int attempts=0;
boolean result=false;
while(attempts<=maxattempts)
{
System.out.println("enter the number between 1 to 100");
int ent=scan.nextInt();
if(ent==a)
{
result=true;
break;
}
else if(ent<a)
{
System.out.println("Too low ..Try again");
}
else
{
System.out.println("Too high ...Try again");
}
attempts++;
}
if(result)
{
System.out.println("Congragulation.. You won the game");
}
else
{
System.out.println("Max attempts tries...Sorry you lost the game ...the number is "+a);
}
}
}