Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Problem_5
- {
- public static void main(String[] args)
- {
- // num is what will look for answer
- // answer will be set to num when found
- // n is for recursively dividing
- int count = 20, ans = 0, n = 2;
- // while the answer has not been found
- // continue searching
- while (ans == 0)
- {
- //System.out.println("Entered loop");
- n = 2;
- // set dividor back to 2 and start again
- while (n <= 20)
- {
- if ((count%n) == 0)
- {
- System.out.println("" + count + " " + n);
- n++;
- }
- else
- n = 21;
- // if num can be modded by 20
- // and if n gets to 20
- // then this must be the answer
- // otherwise the while loop
- // would have stopped
- if ((count % 20 == 0) && (n == 20))
- {
- ans = count;
- System.out.println("The answer is: " + ans);
- }
- }
- count++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment