-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGame.java
More file actions
50 lines (44 loc) · 1.45 KB
/
Copy pathNumberGame.java
File metadata and controls
50 lines (44 loc) · 1.45 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.Random;
import java.util.Scanner;
/**************************CODSOFT-TASK 1(GUESS NUMBER)**************************/
class Game{
int computer;
public Game(){
Random rand=new Random();
computer=rand.nextInt(100);
System.out.println("Guess the Number Form 1 t0 100 : ");
}
public int computerNo(){return computer;}
}
public class NumberGame {
static int TakeuserInput() {
int user;
System.out.println("Enter : ");
Scanner sc = new Scanner(System.in);
user = sc.nextInt();
return user;
}
static void isCorrectNumber(int i,int j){
if (i==j){
System.out.println("Correct No. Guess ");
} else if (i>j) {
System.out.println("Your No. is Bigger than Computer No. ");
}
else {
System.out.println("You No. is Smaller than Computer No. ");
}
}
public static void main(String[] args){
int user=0,computer=0,itteration=0;
Game g=new Game();
do{
user=TakeuserInput();
computer=g.computerNo();
//System.out.println(user);
//System.out.println(computer);
isCorrectNumber(user,computer);
itteration++;
}while (user!=computer);
System.out.println("YOU GUESS NO IS "+computer+ " IN "+itteration+" ITTERATIONS");
}
}