Skip to content
Advertisement

Algorithm to get the submultiples of each number in a range

I have this exercise in mind, I keep trying to solve it in Java but I’m not able to create a correct algorithm to get the submultiples of each number in a range, the start and the end of the range is user defined. Besides, the number 1 doesn’t count as a submultiple.

For example, in a range between 3 and 9, the output of the app would be:

JavaScript

It would be very helpful if someone can help me with this exercise. Thanks for reading!

Advertisement

Answer

You can do it using to nested loops, like this:

JavaScript

Here, we loop through the user entered range, and then found multiples of each number in an inner loop. We keep track of if any multiple was found, using a boolean variable.

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