Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class HighLowGuessingGame {
  4.  
  5.    public static void main(String[] args) {
  6.  
  7.       Random random = new Random();
  8.       Scanner scanner = new Scanner(System.in);
  9.  
  10.       int number = random.nextInt(100)+1;
  11.       int guess = -1;
  12.       int count=0;
  13.  
  14.       while (guess!=number) {
  15.          count=count+1;
  16.          System.out.print("Enter a number between 1 and 100: ");
  17.          guess = scanner.nextInt();
  18.          if (guess<number) {
  19.             System.out.println("Too low, please try again");
  20.          } else if (guess>number) {
  21.             System.out.println("Too high, please try again");
  22.          } else {
  23.             System.out.println("Correct, the number was " + number);
  24.          }
  25.       }
  26.       System.out.println("It took you " + count + " trys.");
  27.    }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement