Advertisement
MrDoyle

Do-While) Again with the Number Guessing

Nov 13th, 2020
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         System.out.println("The worst number guessing game ever!!!! ");
  8.  
  9.         Scanner keyboard = new Scanner (System.in);
  10.         Random random = new Random();
  11.         int rand = 0;
  12.         while (true){
  13.             rand = random.nextInt(11);
  14.             if(rand !=0) break;
  15.         }
  16.         int entry = 0;
  17.         int NumberOfAttempts = 0;
  18.  
  19.         do {
  20.             System.out.println();
  21.             System.out.println("You have guessed " + NumberOfAttempts + " times");
  22.             System.out.println("I´´ thinking of a number from 1-10. Try to guess!");
  23.             entry = keyboard.nextInt();
  24.  
  25.             if (entry == rand) {
  26.                 System.out.println("LOL!! U got it, I can´t believe you guessed it was " + rand +". It only took you " + (NumberOfAttempts + 1) + " tries");
  27.             } else {
  28.                 System.out.println("That is incorrect, please try again!");
  29.             }
  30.             NumberOfAttempts = NumberOfAttempts + 1;
  31.  
  32.         } while ( entry != rand);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement