By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

Novice needs help with maths quiz program

P: 1
Hello all,
For the record I am a complete java novice.

I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows

Random number, Random operator (+ or -) random number.

I have written the program but cannot make the random operator work. Can anyone help?

My code.

a = myRandom.nextInt(8) +11;//generates random number
b = myRandom.nextInt(8) +1;//generates 2nd random number

if(b<4)//this code sets random operator + or -
{
t='-'; // t is the random operator
}
else
{
t='+';
}
System.out.print("Question "+p+": "+((a+t+b)+"= ? "));//prints question to screen

Thanks
Dec 2 '06 #1
Share this Question
Share on Google+
1 Reply


sicarie
Expert Mod 2.5K+
P: 4,677
Hello all,
For the record I am a complete java novice.

I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows

Random number, Random operator (+ or -) random number.

I have written the program but cannot make the random operator work. Can anyone help?

My code.

a = myRandom.nextInt(8) +11;//generates random number
b = myRandom.nextInt(8) +1;//generates 2nd random number

if(b<4)//this code sets random operator + or -
{
t='-'; // t is the random operator
}
else
{
t='+';
}
System.out.print("Question "+p+": "+((a+t+b)+"= ? "));//prints question to screen

Thanks
TwistedSpanner-

Here is a tutorial on random numbers in Java, if you think you have everything right, please post your entire program, and any error messsages you are getting, or what the current output is.

http://www.cs.geneseo.edu/~baldwin/r...ce/random.html
Dec 4 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.