SlowBoatToTokyo

Problem_5_second

Oct 17th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. public class Problem_5
  2. {
  3.  
  4.    
  5.     public static void main(String[] args)
  6.     {
  7.         // num is what will look for answer
  8.         // answer will be set to num when found
  9.         // n is for recursively dividing
  10.         int num = 20, answer = 0, n = 1;
  11.        
  12.         // while the answer has not been found
  13.         // continue searching
  14.         while (answer == 0)
  15.         {
  16.             n = 1;
  17.             // set dividor back to 1 and start again
  18.             while (n <= 20)
  19.             {
  20.                 if ((num % n) == 0)
  21.                     n++;
  22.             }
  23.             if ((num % 20 == 0) && (n == 20))
  24.             {
  25.                 answer = num;
  26.                 System.out.print("The answer is: " + answer);
  27.             }
  28.  
  29.             num++;
  30.         }
  31.            
  32.  
  33.  
  34.     }
  35.  
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment