Javatpoint Logo

91-9990449935

 0120-4256464


Write a program in Java to print the sum of all numbers from n1 to n2 (n1<=n2, inclusive of n1 and n2) that are multiples of 3 and not divisible by 9.

By: utkdub@gmail.com On: Mon Jun 13 14:39:21 IST 2016     0 0 0  0
Write a program in Java to print the sum of all numbers from n1 to n2 (n1<=n2, inclusive of n1 and n2) that are multiples of 3 and not divisible by 9.

Sample input :

230 240

Sample output :

708
0

 
import java.util.Scanner;
class MultiDiv{
public static void main(String args[]){
int n1,n2,sum=0;
Scanner in=new Scanner(System.in);
n1=in.nextInt();
n2=in.nextInt();
for(int i=n1;i<=n2;i++){
if(i%3==0&&i%9!=0){
sum=sum+i;

}


}
System.out.println(sum);
}


}
0

By: utkdub@gmail.com On: Mon Jun 13 14:39:53 IST 2016 0 0 0 0
Are You Satisfied :0Yes0No


PLEASE REPLY

Please login first to post reply. Login please!