public class SumofAlldiviser {
public static void main(String[] args) {
int L=1;
int R=20;
int divisible=6;
int sum=0;
for (int i = L; i < R; i++) {
if(i%divisible==0) {
sum=sum+i;
}
}
System.out.println("sum of all numbers divisible by 6 in given range is : "+sum);
}
}
Output: sum of all numbers divisible by 6 in given range is : 36
Post a Comment