Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Guess My Number
- / Nikki Forehand & Anthony Conner
- */
- import java.util.*;
- public class Program {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Random rng = new Random();
- int secret = rng.nextInt(100) + 1;
- int guess;
- System.out.println("I'm thinking of a number 1 - 100."); // The Number Range
- System.out.print("Enter Guess: "); // Guess a number
- guess = sc.nextInt();
- while(guess != secret) {
- System.out.println("Nope."); // If not the secret number than it says Nope
- if(secret < guess) {
- System.out.println("Hint: lower" ); // If secret number is lower than guess , it says lower
- }
- else {
- System.out.println("Hint: higher" ); //If secret number is Higher than guess , it says Higher
- }
- System.out.print("Guess Again: "); // Guess again if number is wrong
- guess = sc.nextInt();
- }
- System.out.println("You got it!"); // You got the secret number!!!
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement