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 using notepad and command prompt but 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?
Instead of having multiple random number variables I'd just have two that were reset each question and instead of putting the same code over I'd just have it once and on a loop until the 30th question, is this possible to do?
Any help would be appreciated, below is what I have so far - I'd like to emphasis this isn't for school or anything like that, I'm just hoping to learn Java in my free time. Also I don't want somebody to code for me, just point me in the right direction.
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."); }