-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (34 loc) · 1.45 KB
/
Main.java
File metadata and controls
38 lines (34 loc) · 1.45 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
36
37
38
import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
import java.util.Scanner;
/**
* Created by iyasuwatts on 10/17/17.
*/
public class Main {
public static void main(String[] args){
int number = (int) Math.floor(Math.random() * 100);
Scanner input = new Scanner(System.in);
System.out.println("Guess the number I am thinking of. The number is between 1 - 100");
int inputNumber = input.nextInt();
int duplicateNumber = inputNumber;
int count = 0;
while (inputNumber != number) {
if (inputNumber < number) { // check in guess was lower
System.out.println("Your guess was too low! Try again!");
inputNumber = input.nextInt();
if (inputNumber != duplicateNumber) { // check if number is the same as the last number entered
count++;
}
duplicateNumber = inputNumber;
}
if (inputNumber > number) { // check if guess was higher
System.out.println("Your guess was too high! Try again!");
inputNumber = input.nextInt();
if (inputNumber != duplicateNumber) { // check if number is the same as the last number entered
count++;
}
duplicateNumber = inputNumber;
}
}
System.out.println("You guessed the number! It took you " + count + " tries.");
}
}