Advertisement
Hirsw0w

Untitled

Feb 4th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class Main {
  5.  
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner s = new Scanner(System.in);
  10. System.out.println("start math test ? y/n");
  11. String c = s.next();
  12.  
  13. if(c == "n") return;
  14. else StartMath();
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. }
  23.  
  24. private static void StartMath() {
  25.  
  26. Random r = new Random();
  27. Scanner s = new Scanner(System.in);
  28.  
  29. System.out.println("choose a level 1-3");
  30. int level = s.nextInt();
  31. if(level < 1 || level > 3) return;
  32. System.out.println("I will ask you 20 question and you need to answer the most fast as you can - and right!");
  33.  
  34. Date date = new Date();
  35. long d = date.getTime();
  36.  
  37. int num1=0,num2=0;
  38. int correct=0;
  39. for(int i = 1;i <= 20;i++) {
  40. if(level == 1) {
  41. num1 = r.nextInt(10);
  42. num2 = r.nextInt(10);
  43. }
  44. else if(level == 2) {
  45. num1 = r.nextInt(100);
  46. num2 = r.nextInt(100);
  47. }
  48. else {
  49. num1 = r.nextInt(1000);
  50. num2 = r.nextInt(1000);
  51. }
  52.  
  53. System.out.println("Question " + i);
  54. System.out.println(num1 + "-" + num2 + "=?");
  55. int answer = s.nextInt();
  56.  
  57. if(answer == num1-num2) {
  58. correct++;
  59. System.out.println("You answer right! good job!");
  60. }
  61. else System.out.println("Your answer was wrong!");
  62.  
  63.  
  64. }
  65.  
  66. System.out.println("You answer " + correct + " correct and " + (20-correct) + " wrong!");
  67. Date date2 = new Date();
  68. long d2 = date2.getTime();
  69. System.out.println("it take you " + (d-d2));
  70. }
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement