-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessTheNumber.java
More file actions
46 lines (44 loc) · 1.06 KB
/
guessTheNumber.java
File metadata and controls
46 lines (44 loc) · 1.06 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
import java.util.Random;
import java.util.Scanner;
class Game{
int noOfGuess=1;
public void Game(int x,int y,int z){
if(x==y){
System.out.println("Congratulations you won the game in"+noOfGuess+"guess");
}
else if(x>y){
System.out.println("Computer number is greater than"+y);
}
if(x<y){
System.out.println("Computer number is less than"+y);
}
noOfGuess++;
}
}
class guessTheNumber{
public static void main(String args[]){
Random r= new Random();
Scanner sc=new Scanner(System.in);
int cu=r.nextInt(100);
//Game su[]=new Game[5];
//int cu=(int)(Math.random()*(100-1+1)+1);
Game GTN=new Game();
//int noOfGuess=1;
for(int i=1;i<=100;i++){
int a=101-i;
System.out.println("You have "+a+" attempts left");
int u=sc.nextInt();
GTN.Game(cu,u,a);
/*if(cu==u){
System.out.println("Congratulations you won the game in"+noOfGuess+"guess");
}
else if(cu>u){
System.out.println("Computer number is greater than"+u);
}
if(cu<u){
System.out.println("Computer number is less than"+u);
}
noOfGuess++;*/
}
}
}