Advertisement
lol1234561

Untitled

Mar 28th, 2023
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner keyboard = new Scanner(System.in);
  5.  
  6.         int guess = 5;
  7.         int tries = 0;
  8.         System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
  9.         System.out.println("Your guess: ");
  10.         int num = keyboard.nextInt();
  11.         tries++;
  12.         do{
  13.             System.out.println("That is incorrect. Guess again.");
  14.             System.out.println("Your guess: ");
  15.             num = keyboard.nextInt();
  16.             tries++;
  17.         }while (num != guess);
  18.         System.out.println("Congratulations it only took you " +
  19.                 tries + " tries");
  20.     }
  21. }
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement