-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessNumberOneTime.java
More file actions
29 lines (25 loc) · 872 Bytes
/
GuessNumberOneTime.java
File metadata and controls
29 lines (25 loc) · 872 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
import java.util.Scanner;
/**
* Created by Melissa on 20/08/2017.
*/
public class GuessNumberOneTime {
public static void main(String[] args) {
// Generate a random number to be guessed
int number = (int)(Math.random() * 101);
int guess = 0;
Scanner input = new Scanner(System.in);
System.out.println("Guess a magic number between 0 and 100");
while(number != guess)
{
// Prompt the user to guess the number
System.out.print("\nEnter your guess: ");
guess = input.nextInt();
if(guess == number)
System.out.println("Yes, the number is " + number);
else if (guess > number)
System.out.println("Your guess is too high");
else
System.out.println("Your guess is too low");
}
}
}