-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessingGame.java
More file actions
31 lines (28 loc) · 979 Bytes
/
Copy pathGuessingGame.java
File metadata and controls
31 lines (28 loc) · 979 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
import java.util.Scanner;
public class GuessingGame {
int random;
GuessingGame(){
random = (int) Math.ceil(Math.random()*100);
}
int guess(int guessNumber){
return guessNumber - random;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
GuessingGame game = new GuessingGame();
System.out.println("Welcome to the guessing game. Guess the number between 1 to 100");
int guess, result;
do{
System.out.println("Guess the number");
guess = sc.nextInt();
result = game.guess(guess);
if(result == 0){
System.out.println("congrats, you guess the correct");
} else if(result < 0){
System.out.println("Please guess higher");
}else{
System.out.println("Please guess lower");
}
} while(result != 0);
}
}