-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguess_game.java
60 lines (51 loc) · 1.22 KB
/
guess_game.java
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
package com.emranCoder;
import java.util.Random;
import java.util.Scanner;
class Game{
private int userInput,guessNumber=0;
private final int cpu;
Scanner sc = new Scanner(System.in);
public Game()
{
Random rn = new Random();
cpu = rn.nextInt(100);
start();
}
private void getInput()
{
userInput = sc.nextInt();
guessNumber++;
}
private void isCorrectNumber(int x)
{
if(x>cpu)
{
System.out.println("Make it Small!");
start();
} else if(x<cpu) {
System.out.println("Make it bigger!");
start();
}else
{
System.out.println("# You got it right!");
System.out.println("Your Point is: "+ --guessNumber);
}
}
private void start()
{
getInput();
if(0>=userInput || userInput<=100)
{
isCorrectNumber(userInput);
}else
{
start();
}
}
}
public class guess_game {
public static void main(String[] args) {
System.out.println("Guess The Number: ");
Game obj = new Game();
}
}