-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessnumber.java
More file actions
28 lines (22 loc) · 823 Bytes
/
Guessnumber.java
File metadata and controls
28 lines (22 loc) · 823 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
import java.util.Scanner;
public class Guessnumber{
public static void main(String args[]){
int number=(int)(Math.random()*101);
Scanner input = new Scanner(System.in);
int Guess=-1;
//System.out.println(number);
while(Guess!= number){
System.out.println("Guess a magic number between 0 and 101");
Guess = input.nextInt();
if (Guess > number) {
System.out.println("Your guess is too high!");
} else if (Guess < number) {
System.out.println("Your guess is too low!");
}
else if(Guess==number){
System.out.println("Congratulations! You've guessed the right number.");
}
}
System.out.println("Congratulations! You've guessed the right number.");
}
}