-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessNumber.java
More file actions
31 lines (21 loc) · 772 Bytes
/
GuessNumber.java
File metadata and controls
31 lines (21 loc) · 772 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.*;
public class GuessNumber {
public static void main(String[] args) {
int Mynum = (int) (Math.random() * 100);
int usernum;
Scanner sc = new Scanner(System.in);
do {
System.out.print("Guess the Number (1-100) = ");
usernum = sc.nextInt();
if (Mynum == usernum) {
System.out.println("Congratulation You guessed it Right");
break;
} else if (Mynum > usernum) {
System.out.println("Your number is small");
} else if (Mynum < usernum) {
System.out.println("Your number is large");
}
} while (usernum >= 0);
System.err.println("My number is " + Mynum);
}
}