Hi, I am writing a program that generates random maths questions for primary schools, but I'm having a problem finding out how to select one of the following characters at random (+ - * /).
Please can you help?
Thanks.
Printable View
Hi, I am writing a program that generates random maths questions for primary schools, but I'm having a problem finding out how to select one of the following characters at random (+ - * /).
Please can you help?
Thanks.
hi cachi
do one thing convert characters in string[]
and from that u can get your charactor randomly
with help of equals method u can get apropriate operator
ok
Do what was previously stated and use Random.nextInt(4). It will return you either 0,1,2 or 3. You can use that to get one of the symbols from the array.
yes, so to further explain that, it means that
if (x=0)
{
selectedSymbol=plus;
}
...etc
Don't use an if statement at all.
Just loop that last line as you create your math problems.Code:String[] operators = {"+", "-", "*", "/"};
Random rand = new Random();
String op = operators[rand.nextInt(4)];