Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("The worst number guessing game ever!!!! ");
- Scanner keyboard = new Scanner (System.in);
- Random random = new Random();
- int rand = 0;
- while (true){
- rand = random.nextInt(11);
- if(rand !=0) break;
- }
- int entry = 0;
- int NumberOfAttempts = 0;
- while ( entry != rand) {
- System.out.println("You have guessed " + NumberOfAttempts + " times");
- System.out.println("I´´ thinking of a number from 1-10. Try to guess!");
- entry = keyboard.nextInt();
- if (entry == rand) {
- System.out.println("LOL!! U got it, I can´t believe you guessed it was " + rand +". It only took you " + (NumberOfAttempts + 1) + " tries");
- } else {
- System.out.println("That is incorrect, please try again!");
- }
- NumberOfAttempts = NumberOfAttempts + 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement