-
Notifications
You must be signed in to change notification settings - Fork 130
/
Main.java
45 lines (34 loc) · 1017 Bytes
/
Main.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
41
42
43
44
45
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Random;
import java.util.Scanner;
public class Main
{
// instance variables - replace the example below with your own
Random rand = new Random();
Scanner input = new Scanner(System.in);
int number = rand.nextInt(10) + 1;
int count = 0;
int guess = 0;
public Main()
{
System.out.println("Guess a number between 1 and 10: ");
while (guess != number){
guess = input.nextInt();
count++;
if (guess > number) {
System.out.println("Guess lower:");
}
else if (guess < number) {
System.out.println("Guess higher:");
}
else {
System.out.println("Congrats! " + guess + " is the number! You guessed " + count + " times.");
}
}
}
}