-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessingGame.java
More file actions
35 lines (32 loc) · 1.12 KB
/
GuessingGame.java
File metadata and controls
35 lines (32 loc) · 1.12 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
import java.util.Scanner;
public class GuessingGame {
int random;
GuessingGame(){
this.random=(int)Math.ceil(Math.random()*100) ;
}
int guess(int guessNumber){
return guessNumber-random;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
GuessingGame game= new GuessingGame();
System.out.println("Welcome to the Guessing game guess this umber between 1 to 100 !");
int guess,guessNumber,attempt=1;
while(true){
System.out.print("Enter your guess your number : ");
guess= input.nextInt();
guessNumber=game.guess(guess);
if(guessNumber==0){
System.out.printf("Hurry ! you guess this number at %d attempted : %d",attempt,guess);
break;
} else if (guessNumber<0) {
System.out.println("please guess higher number ! ");
}
else {
System.out.println("please guess lower Number !");
}
attempt++;
}
input.close();
}
}