You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//sum all the numbers between 1 to 1000 that are divisible by 7. (Hint: Modify the initialization statement to begin from 7 and post-processing statement to increment by 7. Ans: 71071)
public class RunningNumberMod7Sum {
public static void main(String[] args) {
final int LOWERBOUND = 7; // if you need to sum the nuber divisible by any number, change this one!!!
final int UPPERBOUND = 1000;
int sum = 0;
int number = LOWERBOUND;
while (number <= UPPERBOUND) {
sum = sum + number;
number = number + 7; //here also to tell the program how many number from 1 to count!
}
System.out.println("The sum of " + LOWERBOUND + " to " + UPPERBOUND + " is " + sum);