Created
July 5, 2020 22:42
-
-
Save jpark9013/20cb0ed301fc1d03864bd155f643b5ff to your computer and use it in GitHub Desktop.
guessing game 1-100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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