SlowBoatToTokyo

Problem_1_solution

Oct 17th, 2011
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1.  
  2. public class Problem_1
  3. {
  4.  
  5.    
  6.     public static void main(String[] args)
  7.     {
  8.         // declare ints for number and sum
  9.         int number = 0, sum = 0;
  10.        
  11.         // while the counter is less than 1000, stay in loop
  12.         while(number < 1000)
  13.         {
  14.             // if the new number is divisible by either 3 or 5, add it to total sum
  15.             if (number % 3 == 0 || number % 5 == 0)
  16.                 sum = sum + number;
  17.            
  18.             // count to next number
  19.             number++;
  20.         }
  21.         // print result
  22.         System.out.print("" + sum);
  23.  
  24.     }
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment