Advertisement
Nikki12345671

Guess my number

Feb 13th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. /* Guess My Number
  2. / Nikki Forehand & Anthony Conner
  3. */
  4.  
  5. import java.util.*;
  6.  
  7. public class Program {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. Scanner sc = new Scanner(System.in);
  12. Random rng = new Random();
  13. int secret = rng.nextInt(100) + 1;
  14. int guess;
  15.  
  16. System.out.println("I'm thinking of a number 1 - 100."); // The Number Range
  17.  
  18. System.out.print("Enter Guess: "); // Guess a number
  19. guess = sc.nextInt();
  20.  
  21. while(guess != secret) {
  22. System.out.println("Nope."); // If not the secret number than it says Nope
  23.  
  24. if(secret < guess) {
  25. System.out.println("Hint: lower" ); // If secret number is lower than guess , it says lower
  26. }
  27. else {
  28. System.out.println("Hint: higher" ); //If secret number is Higher than guess , it says Higher
  29.  
  30. }
  31. System.out.print("Guess Again: "); // Guess again if number is wrong
  32. guess = sc.nextInt();
  33.  
  34. }
  35. System.out.println("You got it!"); // You got the secret number!!!
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement