Hi, I recently started programming with java and I was doing a code where two random numbers from 1-10 would be chosen and then a random operator would be chosen as well, the user would have to input the answer to the question and the program is suppose to check if its correct or not.
import java.util.Random;
import java.util.Scanner;
/** * Johan Biesert * Project Chapter 4 * Part 1 * October 30 2018 */ public class Part_2 { public static void main(String[] args) { //variables int First; int Second; int random1; int operator; int calc; int ans; First = (int) (( 10 - 1 + 1) *Math.random() + 1); Second = (int) (( 10 - 1 + 1) *Math.random() + 1); random1 = (int) (( 4 - 1 + 1) *Math.random() + 1); operator = ' '; switch (operator) { case 1: operator = '+'; break; case 2: operator = '-'; break; case 3: operator = '*'; break; case 4: operator = '/'; break; if (random1 == 1) { [B]Error starts here[/B] operator = 1; } else if (random1 == 2) { operator = 2; } else if (random1 == 3) { operator = 3; } else if (random1 == 4) { operator = 4; System.out.println("solve the following"); System.out.println(First + operator + Second); calc = (First + operator + Second); Scanner input = new Scanner(System.in); ans = input.nextInt(); input.close(); if (ans == calc) { System.out.println("correct"); } else { System.out.println("incorrect"); } } } } }