Note that there are some explanatory texts on larger screens.

plurals
  1. POFind a random integer which creates another integer, when using percentages
    text
    copied!<p><strong>Solved, for the precise solution for my problem, see my answer</strong></p> <p>I am sorry about the confusing title, let me clarify my problem:</p> <p>My Java program is supposed to ask a math question with percentages.</p> <p>It should create a question in this format:</p> <pre><code>25% of 4616 = ? </code></pre> <p>The requirements are:</p> <ul> <li>the percentage is always dividable by 5 (no problem)</li> <li>the number (here 4616) has to be between 100 and 9999 (also not a problem)</li> <li>the number as well as the result has to be an integer (this is my problem)</li> </ul> <p>Is there any fast method to find a random number which fulfills the last requirement?</p> <p>The only solution I can think of is to find the percentage, then create a loop which will not stop until a random number is found which fulfills the requirement (in the example until <code>number % 4 == 0</code> is true)</p> <p>But this loop could run thousands of times until a correct number is found.</p> <p>Is there a better method for my problem?</p> <p><strong>Edit:</strong> It seems that I didn't make clear what my problem is, I don't want double numbers as a result, only integer.</p> <p>E.g.: If my percentage is 65%, then a possible question would be </p> <blockquote> <p>65% of 7620 = ?</p> </blockquote> <p>because the solution 4953 is also a whole number.</p> <p>I want to find a random number between 100 and 9999 which is a whole number AND has a whole number as a result to the equation p * x = y.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload