View Full Version : math problem with java

02-17-2003, 12:33 PM
hi to all,

i have written a simple calc that displays times tables or it generates random problems of different operators (i.e., + - x /)
the problem is the random numbers that are generated do not always result in an integer answer, so u get problems like 10 / 7 = 1. if i use doubles the answer is 1.42857......... but this is for a forth class student so i only want problems that will result in an integer answer that is correct not like 10 / 7 = 1.

is there an easy waay to do this.

apart from this my first console attempt works fine just need to adapt to applet.

thanx to all in advance

kind regards,


Josh Campbell
02-17-2003, 08:39 PM
when you are dividing, first check to see if the two numbers produce a remainder. If they do, pick new numbers.

You use the mod operator % to find remainder. If randomIntA % randomIntB == 0 then there is no remainder.

02-18-2003, 03:05 AM
thanx josh,

i had a blackout and couldnt get online :(

but i already figured it out by using the modulus

great minds think alike :thumbsup:

thanx again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum