-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.java
More file actions
35 lines (30 loc) · 1.25 KB
/
Copy pathtask1.java
File metadata and controls
35 lines (30 loc) · 1.25 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
import java.util.Scanner;
import java.util.Random;
public class task1 {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
String play = "yes";
while (play.equals("yes")) {
Random cello = new Random();
int celloNum = cello.nextInt(100) + 1; // Random number between 1 and 100
int guess = 0;
int tries = 0;
while (guess != celloNum) {
System.out.print("Enter your guess: ");
guess = reader.nextInt();
tries++;
if (guess > celloNum) {
System.out.println("Your guess is too high, try again.");
} else if (guess < celloNum) {
System.out.println("Your guess is too low, try again.");
} else {
System.out.println("Awesome! Your guess is good.");
System.out.println("It only took you " + tries + " tries!");
}
}
System.out.print("Would you like to play again? (yes/no): ");
play = reader.next().toLowerCase();
}
reader.close();
}
}