Skip to content
Advertisement

(Java) Generating random number for division program

Hi I’m new to programming and I’m trying to make a division program that can generate 2 random numbers and the condition is that the first number must be more than the second and they give no remainder. If the number generated does not meet the condition it keeps generating until the conditions are met. Can anyone help me fix my error?

JavaScript

Advertisement

Answer

Your while condition checks that the division result is even randomnum1/randomnum2 % 2 != 0
You should replace :

JavaScript

With

JavaScript

As rand1 modulo rand2 == 0 means that

they give no remainder

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement