Advertisement
Guest User

CHDHSguess1

a guest
Oct 23rd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class Problem2 {
  4.  
  5. public static void main(String[] args)
  6. {
  7.  
  8. Scanner userinput = new Scanner(System.in);
  9. Random rand = new Random();
  10. int randint = rand.nextInt(10);
  11. int guess = 0;
  12. System.out.println("Guess a number between 1 and 10:");
  13. guess = userinput.nextInt();
  14. while (guess != randint) {
  15. System.out.println("Incorrect, Try again:");
  16. guess = userinput.nextInt();
  17. }
  18. System.out.println("You've guessed the number!");
  19. System.out.println("You win!");
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement