SlowBoatToTokyo

Problem_5_second_revisit

Oct 19th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 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 count = 20, ans = 0, n = 2;
  11.        
  12.         // while the answer has not been found
  13.         // continue searching
  14.         while (ans == 0)
  15.         {
  16.             //System.out.println("Entered loop");
  17.             n = 2;
  18.             // set dividor back to 2 and start again
  19.             while (n <= 20)
  20.             {
  21.                 if ((count%n) == 0)
  22.                 {
  23.                     System.out.println("" + count + " " + n);
  24.                     n++;
  25.                 }
  26.                 else
  27.                     n = 21;
  28.             }
  29.             // if num can be modded by 20
  30.             // and if n gets to 20
  31.             // then this must be the answer
  32.             // otherwise the while loop
  33.             // would have stopped
  34.             if ((count % 20 == 0) && (n == 20))
  35.             {
  36.                 ans = count;
  37.                 System.out.println("The answer is: " + ans);
  38.             }
  39.  
  40.             count++;
  41.         }
  42.            
  43.  
  44.  
  45.     }
  46.  
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment