Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ISMAIL {
  3. public static void main(String[] args){
  4. Scanner scan=new Scanner(System.in);
  5. int array1[]=new int[10];
  6. for (int i=0;i<array1.length;i++){
  7. array1[i]=i+1;
  8. }
  9. long start = System.currentTimeMillis();
  10. int numbercorrect=0;
  11. int numberincorrect=0;
  12. for(int a=0;a<60;a++){
  13. int operator=0;
  14. String operator2=" ";
  15. int x=array1[(int)(Math.random()*9+1)];
  16. int y=array1[(int)(Math.random()*9+1)];
  17. if((int)(Math.random()*9+1)<=5){
  18. operator=x+y;
  19. operator2="+";
  20. System.out.println(Integer.toString(x)+operator2+Integer.toString(y));
  21. }
  22. else{
  23. operator2="-";
  24. if(x>y){
  25. operator=x-y;
  26. System.out.println(Integer.toString(x)+operator2+Integer.toString(y));
  27. }
  28. else{
  29. operator=y-x;
  30. System.out.println(Integer.toString(y)+operator2+Integer.toString(x));
  31. }
  32. }
  33. System.out.println("Please enter your answer");
  34. int answer=scan.nextInt();
  35.  
  36. if(answer==operator){
  37. System.out.println("WELL DONE!!!!");
  38. numbercorrect++;
  39. }
  40. else{
  41. System.out.println("Wrong");
  42. printfunction(x,y,operator2);
  43. numberincorrect++;
  44. }
  45. System.out.println("Would you like to end the game");
  46. String endgame=scan.next();
  47. if(endgame=="N"||endgame=="n"){
  48. break;
  49. }
  50. }
  51. long end = System.currentTimeMillis();
  52. float difference=(float)((end-start)/1000);
  53. int score=(int)(difference*numbercorrect*60);
  54. System.out.println("\n");
  55. System.out.println("Your score was"+score);
  56. System.out.println("\n");
  57. System.out.println("You got "+numbercorrect+"correct and "+numberincorrect+"incorrect");
  58. }
  59. public static void printfunction(int a, int b, String c){
  60. int x=0;
  61. int y=0;
  62. if(c=="+"){
  63. for (int i=0;i<a;i++){
  64. System.out.print("()");
  65. }
  66. System.out.println();
  67. for (int i=0;i<b;i++){
  68. System.out.print("()");
  69. }
  70. System.out.println();
  71. for (int i=0;i<a+b;i++){
  72. System.out.print("()");
  73. }
  74. }
  75. else{
  76. if(a>b){
  77. x=a;
  78. y=b;
  79. }
  80. else{
  81. x=b;
  82. y=a;
  83. }
  84. for (int i=0;i<x;i++){
  85. System.out.print("()");
  86. }
  87. System.out.println();
  88. for (int i=0;i<y;i++){
  89. System.out.print("()");
  90. }
  91. System.out.println();
  92. for (int i=0;i<x;i++){
  93. System.out.print("()");
  94. }
  95. for (int i=0;i<y;i++){
  96. System.out.print("(/)");
  97. }
  98. System.out.println();
  99. for (int i=0;i<x-y;i++){
  100. System.out.print("()");
  101. }
  102. System.out.println();
  103. }
  104. }
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement