Skip to content

Instantly share code, notes, and snippets.

@jpark9013
Created July 5, 2020 22:42
Show Gist options
  • Save jpark9013/20cb0ed301fc1d03864bd155f643b5ff to your computer and use it in GitHub Desktop.
Save jpark9013/20cb0ed301fc1d03864bd155f643b5ff to your computer and use it in GitHub Desktop.
guessing game 1-100
import java.util.*;
public class Hello {
public static void main(String[] args) {
Random rand = new Random();
int tries = 1;
int num = rand.nextInt(99) + 1;
Scanner sc = new Scanner(System.in);
System.out.println("Guess a number between 1 and 100");
int plr = Integer.parseInt(sc.nextLine());
while (plr != num) {
if (plr < num) {
System.out.println("Too low");
} else if (plr > num) {
System.out.println("Too high");
}
plr = Integer.parseInt(sc.nextLine());
tries++;
}
System.out.println("Correct. Number of tries you took is " + tries);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment