Advertisement
JackHoughton00

Guessing Game.

Apr 10th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package actualmethodguessing;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4. public class ActualMethodGuessing {
  5.  
  6. public static void main(String[] args) {
  7. Scanner input = new Scanner(System.in);
  8. Random rand = new Random();
  9. int guessNum = rand.nextInt(20);
  10. int num, findNum = 0;
  11. findNum = guessNum;
  12. boolean again;
  13. System.out.print("This is a guessing game...");
  14. System.out.print("\nPlease enter a number between one and twenty:");
  15. do {
  16. num = input.nextInt();
  17. if (num==findNum){
  18. System.out.println("Congrats you guessed the right number!");
  19. again = false;
  20. } else {
  21. System.out.println("Whoops! You did NOT guess the right number! :( ");
  22. again = true;
  23. giveHint(num,findNum);
  24.  
  25. }
  26. } while (again);
  27. input.close();
  28. System.out.println("The actual number was"+findNum);
  29. System.out.println("Your number was "+num);
  30. }
  31.  
  32. public static void giveHint(int num, int findNum ) {
  33. if (findNum>num){
  34. System.out.print("Hint: guess a higher number. ");
  35. } else if (findNum<num){
  36. System.out.print("Hint: guess a lower number. ");
  37.  
  38. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement