Advertisement
CamiloCastilla

Untitled

Dec 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner keyboard = new Scanner(System.in);
  9.         int pin = 3;
  10.         int numberofguesses=0;
  11.         int entry = 0;
  12.  
  13.         System.out.println("\nI have chosen a number between 1 and 10");
  14.  
  15.         do{
  16.  
  17.             System.out.print("Your guess: ");
  18.             entry = keyboard.nextInt();
  19.  
  20.             if ( entry == pin) {
  21.  
  22.             } else {
  23.                 System.out.println("That is incorrect. Guess again!");
  24.             }
  25.             numberofguesses++;
  26.         }
  27.         while (entry != pin);
  28.  
  29.         System.out.println("You are correct!");
  30.         System.out.println("It only took you " + numberofguesses + " guesses");
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement