-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGame.java
More file actions
36 lines (31 loc) · 1.19 KB
/
NumberGame.java
File metadata and controls
36 lines (31 loc) · 1.19 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
package numberGame;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean hasEqual=false;
int randomNumber = (int) (Math.random()*100) + 1; // Assigning a random Number to randomNumber Variable
System.out.println("I have chosen a random Number from 1 to 100.");
System.out.println("Try to Guess it and you win.");
for(int i=10; i>0; i--)
{
System.out.println("You have "+i+" guess(es) left, Guess again: ");
int guess = input.nextInt();
System.out.println("Your guess was "+guess+".");
if(guess>randomNumber)
System.out.println("It is less than "+guess+".");
else if(guess<randomNumber)
System.out.println("It is greater than "+guess+".");
else {
hasEqual = true;
break;
}
}
if(hasEqual)
System.out.println("Correct...You Win!!!");
else{
System.out.println("Game Over....You Lose!!!");
System.out.println("The Number was "+randomNumber+".");
}
}
}