Display sum of numbers which are divisible either by 3 or 5 between 1 to 100 in java without using array
Answers
Answered by
1
public class Divisibilty{
public static void main(String args[]){
int sum =0;
for (int num = 1; num <=100; num++){
if ((num % 3 ==0 )||( num % 5 == 0)){
sum = sum+ num;
}
}
System.out.println("Sum is: "+sum);
}
}
public static void main(String args[]){
int sum =0;
for (int num = 1; num <=100; num++){
if ((num % 3 ==0 )||( num % 5 == 0)){
sum = sum+ num;
}
}
System.out.println("Sum is: "+sum);
}
}
rishilaugh:
thank you very much
Similar questions