SlowBoatToTokyo

Problem_5_Solution

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