Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import java.util.Random;
import java.util.Scanner;

/**
* Created by iyasuwatts on 10/17/17.
*/
public class Main {

public static void main(String[] args){


Random rand = new Random();
int correctNum = rand.nextInt(10) +1;

int giveNum = Integer.MIN_VALUE;
int tries = 1;

Scanner num = new Scanner(System.in);
System.out.println("Guess a number between 1 and 10");
while (giveNum != correctNum) {
String answer = num.nextLine();
giveNum = Integer.parseInt(answer);
System.out.println("Your input was " + answer);

if (giveNum == correctNum) {
System.out.println("Correct guess");
}
else if(giveNum > correctNum){
System.out.println("Too big \n Try again");
tries++;
}
else if(giveNum < correctNum){
System.out.println("Too low \n Try again");
tries++;
}
}
System.out.println("The correct number was " + correctNum);
System.out.println("You guessed " + tries +" time(s)");


}
}
}