Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Problem2 {
- public static void main(String args[]){
- Scanner input = new Scanner(System.in);
- Random rand = new Random();
- int number;
- int guess = 0;
- int counter=0;
- number = rand.nextInt(100)+1;
- while(guess!=number){
- System.out.println("Pick a number from 1 to 100.");
- guess = input.nextInt();
- if(guess>number)
- System.out.println("Your guess is high.");
- else if(guess<number)
- System.out.println("Your guess is low.");
- else
- System.out.println("You guessed it.");
- counter++;
- }
- System.out.println("Number of tries: " + counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement