Guest User

Untitled

a guest
Nov 27th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner keyboard = new Scanner(System.in);
  8.  
  9.         Random rand = new Random();
  10.  
  11.         int guess;
  12.  
  13.         int tries = 1;
  14.  
  15.         int number = 4;
  16.  
  17.  
  18.         System.out.println("\n I have chosen a number between 1 and 10.  Try to guess it.");
  19.  
  20.         //number = rand.nextInt(10);
  21.  
  22.         do{
  23.             System.out.println("\n Guess "+tries+":");
  24.             guess = keyboard.nextInt();
  25.             tries = tries + 1;
  26.         }
  27.         while (guess != number);{
  28.  
  29.             System.out.println("\n That is incorrect.  Guess again.");
  30.  
  31.             System.out.println("\n Guess "+tries+":");
  32.             guess = keyboard.nextInt();
  33.             tries = tries + 1;
  34.         }
  35.  
  36.  
  37.         if (guess == number){
  38.  
  39.             System.out.println("\n That's right!  You're a good guesser.");
  40.             System.out.println("It took you "+tries+" tries to guess right!");
  41.         }
  42.  
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment