Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Monday, August 6, 2012

CJ-15:Numbers divisible by 7, and its sum(1)

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************

import java.io.*;
class div
{
public static void main(String args[])
{
   int sum=0,ct=0,n,i=0;
   try
   {
DataInputStream s=new DataInputStream(System.in);
System.out.println("Enter Limit :");
n=Integer.parseInt(s.readLine());
System.out.println("Numbers divisible by 7 are :");
do
{
   if(i%7==0)
   {
System.out.println(i);
ct++;
sum=sum+i;
   }
   i++;
}
while(i<=n);
System.out.println("Sum = "+sum);
System.out.println("Total Numbers divisible by 7 is : "+ct);
    }
    catch(Exception e)
    {
    }
}
}   
=========================================================================
Output :
Enter Limit:
50
Numbers divisible by 7 are :
0
7
14
21
28
35
42
49
Sum = 196
Total Numbers divisible by 7 is : 8



No comments: