Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem1
- {
- public static void main (String [] args)
- {
- Scanner user_input = new Scanner (System.in);
- int rand;
- int guessNum;
- rand = (int)(Math.random() * 101);
- System.out.print ("I have a number between 1 and 100");
- System.out.println ("\n");
- System.out.print ("What is your guess: ");
- guessNum = user_input.nextInt ();
- int count = 1;
- do
- {
- if (guessNum > rand)
- {
- System.out.print ("Go lower!");
- System.out.print ("\nWhat is your guess: ");
- guessNum = user_input.nextInt ();
- }
- if (guessNum < rand)
- {
- System.out.print ("Go higher!");
- System.out.print ("\nWhat is your guess: ");
- guessNum = user_input.nextInt ();
- }
- if (guessNum == rand)
- {
- System.out.print ("You got it!");
- }
- count ++;
- } while (guessNum != rand);
- System.out.println ("\n");
- System.out.print ("It took " + count + " guesses");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement