-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNumberGuessingGame.java
More file actions
63 lines (57 loc) · 1.92 KB
/
NumberGuessingGame.java
File metadata and controls
63 lines (57 loc) · 1.92 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
import java.util.Scanner;
public class NumberGuessingGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int myNumber = (int)(Math.random()*100);
int k;
System.out.println("Starting the game in few Seconds ");
try{
Thread.sleep(2500);
}catch(InterruptedException ex)
{
ex.printStackTrace();
}
int userNumber = 0;
do {
System.out.println("Guess my number(1-100) : ");
userNumber = sc.nextInt();
if(userNumber == myNumber) {
System.out.println("WELL DONE.. CORRECT NUMBER!!!");
break;
}
else if(userNumber > myNumber) {
System.out.println("your number is too large");
System.out.println("Do you Still want to play enter 1 else 0");
k=sc.nextInt();
if(k==1){
continue;
}
if(k==0){
break;
}
else{
System.out.println("You have chosen Wrong choise so we are closing the game ");
break;
}
}
else {
System.out.println("your number is too small");
System.out.println("Do you Still want to play enter 1 else 0");
k=sc.nextInt();
if(k==1){
continue;
}
if(k==0){
break;
}
else{
System.out.println("You have chosen Wrong choise so we are closing the game ");
break;
}
}
} while(userNumber >= 0);
System.out.println("Thank You For Playing with us..");
System.out.print("My number was : ");
System.out.println(myNumber);
}
}