Advertisement
Blonk

Untitled

Dec 9th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.*;
  2. public class Main {
  3.     public static void main(String[] args){
  4.         Scanner keyboard = new Scanner(System.in);
  5.         Random r = new Random();
  6.  
  7.         int Low = 1;
  8.         int High = 10;
  9.         int actual = 3;
  10.  
  11.         System.out.println("I have chosen a number between 1 and 10.  Try to guess it.");
  12.         int attempt = 1;
  13.         System.out.print("Your guess: ");
  14.  
  15.         int guess = keyboard.nextInt();
  16.  
  17.         do
  18.             {
  19.             if(guess!=actual){
  20.                 System.out.println("That is incorrect. Guess again.");
  21.                 System.out.print("Your guess: ");
  22.                 guess = keyboard.nextInt();
  23.                 attempt++;
  24.             }
  25.         } while(guess!=actual);
  26.  
  27.         System.out.println("That's right!  You're a good guesser.");
  28.         System.out.println("It took you "+ attempt +" tries.");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement