Can't get 2 different randoms
Making a simple maths game that takes a user input as an answer for the sum of two randomly generated numbers.
Each time i run it, i get 7+7, 2+2, 3+3 etc, but never two different numbers.
Any help would be much appreciated
public class Q3
public static void main (String  args)
double first = Math.random()*10;
int firstNumber = (int)first;
double second = Math.random()*10;
int secondNumber = (int)second;
String userAnswerString = JOptionPane.showInputDialog("What is the sum of: " + firstNumber + "+" + secondNumber + " ?");
double userAnswerDouble = Double.parseDouble(userAnswerString);
int answer = (int)userAnswerDouble;
if (answer == (firstNumber + secondNumber))
System.out.println("Congratulations! You are Correct!");
System.out.println("Sorry, that is wrong! The correct answer was: " + (firstNumber+secondNumber));
Re: Can't get 2 different randoms
Please read the Announcement topic at the top of the sub-forum to learn how to post your code in code or highlight tags.
I ran your code a couple times and always got two different numbers. Ensure you're running the latest version of your program. Delete all *.class files and recompile if you have to.