forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessTheNumberGame.java
More file actions
34 lines (30 loc) · 878 Bytes
/
GuessTheNumberGame.java
File metadata and controls
34 lines (30 loc) · 878 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
import java.util.*;
class GuessTheNumberGame
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Random rm = new Random();
int cc = rm.nextInt(1,100);
int uc,count=0;
System.out.println("Guess the number : ");
for(;;)
{
uc = sc.nextInt();
count++;
if(uc==cc)
{
System.out.println("You guessed the number in "+count+" turns.");
break;
}
else if(uc<cc)
{
System.out.println("This number is less than computer's.\nTry again :");
}
else if(uc>cc)
{
System.out.println("This number is greater than computer's.\nTry again :");
}
}
}
}