-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandomGeneratorAS.java
40 lines (27 loc) · 968 Bytes
/
randomGeneratorAS.java
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
37
38
39
40
import java.util.Scanner;
import java.util.Random;
public class randomGeneratorAS {
public static void main(String[] args) {
var reader = new Scanner(System.in);
var randGenerator = new Random();
var num=randGenerator.nextInt(10)+1;
System.out.print("Guess a number from 1 to 10");
var guess = reader.nextInt();
if(guess==num)
System.out.print("You guessed "+num+" which is correct");
while (guess != num) {
if (guess<num){
System.out.print("The number is higher than that");
}
else if(guess>num){
System.out.print("The Number is lower than that");
}
else if(guess==num){
System.out.print("You guessed "+num+" which is correct");
break;
}
System.out.print("Guess again 1 to 10");
guess = reader.nextInt();
}
}
}