Q:

Calculate natural numbers that are divide by 7 & 8 using Java

0

This Program is used to calculate the natural numbers that are divide by 7 & 8 using Java.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

//NATURALS NUMBERS THAT ARE DIVISIBLE BY 7 & 8 

import java.io.*; 

class ssvnat 
{ 
public static void main(String arg[]) throws IOException 
{ 
int i,a,b,s=0,start,end; 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("\n\t\t*** NATURALS NUMBERS THAT ARE DIVISIBLE BY 7 & 8 *** \n"); 
System.out.print("Enter the number will be started : "); 
start=Integer.parseInt(br.readLine()); 
System.out.print("Enter the number to be end : "); 
end=Integer.parseInt(br.readLine()); 
for(i=start;i<=end;i++) 
{ 
a=i%7; 
b=i%8; 
if((a==0)&&(b==0)) 
{ 
System.out.print("\t" + i); 
s=s+i; 
} 
} 
System.out.print("\n\nThe Sum of Numbers that are divisible by 7 and 8 : " + s); 
System.out.println(); 
} 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now