Advertisement
willieshi232

Untitled

Oct 29th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.*;
  2. public class AddingGame
  3. {
  4. public static void main(String[] args)
  5. {
  6. int incorrect = 0;
  7. Random number = new Random();
  8. Scanner pikachu = new Scanner(System.in);
  9. int right = 0;
  10. while(incorrect < 3)
  11. {
  12. int answer = 0;
  13. for(int count = 1; count<=number.nextInt(5 - 2 + 1) + 2; count++)
  14. {
  15. int question = number.nextInt(100);
  16. System.out.print(question + "+");
  17. answer = answer + question;
  18. }
  19. System.out.print("0 = ");
  20. int yourAnswer = pikachu.nextInt();
  21. if(yourAnswer != answer)
  22. {
  23. System.out.println("Wrong! The correct answer was: " + answer);
  24. incorrect ++;
  25. }
  26. else
  27. {
  28. right ++;
  29. }
  30. }
  31. System.out.println("You got " + right + " correct! Good job! Thanks for playing!");
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement