Advertisement
waytoofoxy

Untitled

Mar 29th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3. public class Problem2 {
  4.     public static void main(String args[]){
  5.         Scanner input = new Scanner(System.in);
  6.         Random rand = new Random();
  7.         int number;
  8.         int guess = 0;
  9.         int counter=0;
  10.         String playagain;
  11.         number = rand.nextInt(100)+1;
  12.         while(guess!=number && guess != 101){
  13.         System.out.println("Pick a number from 1 to 100. Type 101 to quit.");
  14.             guess = input.nextInt();
  15.             if(guess>number){
  16.                 System.out.println("Your guess is high.");
  17.             }else if(guess<number){
  18.                 System.out.println("Your guess is low.");
  19.             }else if(guess == 101){
  20.                 System.out.println("Type y to play again.");
  21.                 playagain = input.nextLine();
  22.             }else{
  23.                 System.out.println("You guessed it.");
  24.                 System.out.println("Type y to play again");
  25.             }
  26.             counter++;
  27.         }
  28.         System.out.println("Number of tries: " + counter);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement