Advertisement
binibiningtinamoran

Sample

Oct 29th, 2020
1,818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Sample {
  4.  
  5.     public static int lvlOne() {
  6.         int max = 9, min = 0;
  7.         return (int)(Math.random() * (max - min + 1) + min);
  8.     }
  9.  
  10.     public static int lvlTwo() {
  11.         int max = 99, min = 10;
  12.         return (int)(Math.random() * (max - min + 1) + min);
  13.     }
  14.  
  15.     public static void main(String[] args) {
  16.  
  17.         Scanner input = new Scanner(System.in);
  18.         int random1, random2;
  19.  
  20.         int[] marks = new int[2];
  21.         float total = 0;
  22.  
  23.         int right_ans = 0;
  24.         int wrong_ans = 0;
  25.  
  26.         for(int i = 0; i < marks.length; i++) {
  27.  
  28.             random1 = lvlOne();
  29.             random2 = lvlOne();
  30.  
  31.             int realAns = random1 + random2;
  32.             marks[i] = realAns;
  33.  
  34.             System.out.println((i+1) + ") What is " + random1 + " + " + random2);
  35.             int ans = input.nextInt();
  36.  
  37.             if (ans == realAns) {
  38.                 right_ans += 1;
  39.             } else {
  40.                 wrong_ans += 1;
  41.             }
  42.         }
  43.         for (int mark : marks) {
  44.             System.out.println(mark);
  45.         }
  46.  
  47.         System.out.println("Your total score is: " + right_ans + '\n' + "Correct Answer: " + right_ans);
  48.         System.out.println("Wrong Answer: " + wrong_ans);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement