Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Problem_1
- {
- public static void main(String[] args)
- {
- // declare ints for number and sum
- int number = 0, sum = 0;
- // while the counter is less than 1000, stay in loop
- while(number < 1000)
- {
- // if the new number is divisible by either 3 or 5, add it to total sum
- if (number % 3 == 0 || number % 5 == 0)
- sum = sum + number;
- // count to next number
- number++;
- }
- // print result
- System.out.print("" + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment