Ok, so I searched for a similar thread like this one but couldn't find the answer I'm looking for.
I'm trying to program something that generates random numbers and turns them into a question. I'm not even sure it's even properly written but I'm having a compilation error.
"Variable answer1 might not have been initialized"
Here's the code :
import java.util.Scanner;
import java.util.Random;
public class random{
public static void main (String [] args){
System.out.println("Random number generated");
Random obj= new Random();
Scanner scan = new Scanner(System.in);
int answer1;
int rgen= obj.nextInt(100);
int rgen1= obj.nextInt(1000);
System.out.println(rgen + " + " + rgen1 + " = ? ");
scan.nextInt();
if (answer1 == rgen + rgen1)
System.out.println("Correct");
else
System.out.println("Wrong");
}
}