July 04, 2013

Java program for divisible by 7


Write a program that displays the integers between n number that are divisible by 7

DIVISIBLE BY 7


import java.io.*;

class divi7
{
    public static void main(String args[])throws IOException
    {
       BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
       System.out.println("Enter the limit from:");
       int no=Integer.parseInt(st.readLine());
       System.out.println("Enter the limit to:");
       int n2=Integer.parseInt(st.readLine());
       int sum=0;
    
  for(int i=no;i<n2;i++)
        {
           int rem=i%7;
           if(rem==0)
          {
           System.out.println(i);
                sum=sum+i;           
          }
       }
        System.out.println("The sum of integer between "+no+" and "+n2+" is "+sum);
   }
}


OUTPUT


C:\Program Files\Java\jdk1.5.0\bin>java divi7
Enter the limit from:
100
Enter the limit to:
200
105
112
119
126
133
140
147
154
161
168
175
182
189
196
The sum of integer between 100 and 200 is 2107 
No comments:
Write comments