Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 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. Scanner keyboard = new Scanner(System.in);
  7. Random r = new Random();
  8. int actual= r.nextInt(10);
  9. System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
  10. int tries=1;
  11. System.out.print("Your guess: ");
  12. int guess = keyboard.nextInt();
  13. do{
  14. if(guess!=actual){
  15. System.out.println("That is incorrect. Guess again.");
  16. System.out.print("Your guess: ");
  17. guess = keyboard.nextInt();
  18. tries++;
  19. }
  20. }while(guess!=actual);
  21. System.out.println("That's right! You're a good guesser.");
  22. System.out.println("It took you "+tries+" tries.");
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement