Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Sample {
- public static int lvlOne() {
- int max = 9, min = 0;
- return (int)(Math.random() * (max - min + 1) + min);
- }
- public static int lvlTwo() {
- int max = 99, min = 10;
- return (int)(Math.random() * (max - min + 1) + min);
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int random1, random2;
- int[] marks = new int[2];
- float total = 0;
- int right_ans = 0;
- int wrong_ans = 0;
- for(int i = 0; i < marks.length; i++) {
- random1 = lvlOne();
- random2 = lvlOne();
- int realAns = random1 + random2;
- marks[i] = realAns;
- System.out.println((i+1) + ") What is " + random1 + " + " + random2);
- int ans = input.nextInt();
- if (ans == realAns) {
- right_ans += 1;
- } else {
- wrong_ans += 1;
- }
- }
- for (int mark : marks) {
- System.out.println(mark);
- }
- System.out.println("Your total score is: " + right_ans + '\n' + "Correct Answer: " + right_ans);
- System.out.println("Wrong Answer: " + wrong_ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement