Skip to content

Too large too small #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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)");


}
}
}