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
32 changes: 30 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
import java.util.Scanner;
import java.util.Random;

/**
* Created by iyasuwatts on 10/17/17.
*/



public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter a number between 1 and 10.");

Random generator = new Random();
int min = 1;
int max = 10;
int randomlyGeneratedNumber = min + generator.nextInt(max);

boolean didTheyGuessCorrectly = false;
int count = 0;

public static void main(String[] args){

while (!didTheyGuessCorrectly) {
int usersGuess = input.nextInt();
count++;
if (usersGuess > randomlyGeneratedNumber) {
System.out.println("Sorry. Your guess was too big. Please try again.");
} else if (usersGuess < randomlyGeneratedNumber) {
System.out.println("Sorry. Your guess was too small. Please try again.");
} else if (usersGuess == randomlyGeneratedNumber){
System.out.println("Congratulations! You are correct. It took you exactly " + count + " tries." +
"\nHave a nice day.");
didTheyGuessCorrectly = true;
}
}
}
}