Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- Random random = new Random();
- int rand = 0;
- while (true) {
- rand = random.nextInt(10);
- if (rand != 0) break;
- }
- int numberofguesses=0;
- int entry = 0;
- System.out.println("\nI have chosen a number between 1 and 10");
- do{
- System.out.print("Your guess: ");
- entry = keyboard.nextInt();
- if ( entry == rand) {
- } else {
- System.out.println("That is incorrect. Guess again!");
- }
- numberofguesses++;
- }
- while (entry != rand);
- System.out.println("You are correct!");
- System.out.println("It only took you " + numberofguesses + " guesses");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement