I've never used Java before today so I'm really clueless about the possibilities and such, I've made a really simple math quiz and I'm wondering if there is a better way to make it have more questions other than adding each one manually.
Is there anything that would let me massively condense the amount of code needed for say 30 questions, or any way to let the user input how many questions they want at the start and have that amount created?
I'm guessing that's what Arrays are used for, but I haven't really been able to find any easy to follow articles on using them - I learn alot better by seeing a practical example and changing it through trial and error.
Any help would be appreciated, below is what I have so far.
import java.io.*;
import java.util.*;
class Test2 {
public static void main (String[] args) throws IOException {
BufferedReader Answer = new BufferedReader
(new InputStreamReader(System.in));
int num1, num2, correct1, correct2, score;
int a = (int)(5.0 * Math.random()) + 5;
int b = (int)(5.0 * Math.random()) + 5;
int c = (int)(5.0 * Math.random()) + 5;
int d = (int)(5.0 * Math.random()) + 5;
System.out.print ("What is " +a+ " * " +b+ "? ");
System.out.flush();
num1 = Integer.parseInt( Answer.readLine());
if(num1 == a * b)
{
correct1 = 1;
}
else{
correct1 = 0;
}
System.out.print ("What is " +c+ " * " +d+ "? ");
System.out.flush();
num2 = Integer.parseInt( Answer.readLine());
if(num2 == c * d)
{
correct2 = 1;
}
else
{
correct2 = 0;
}
score = correct1 + correct2;
System.out.println("You scored " + score + " out of 2.");
}