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

Wednesday, August 15, 2012

CJ-16 : Numbers divisible by 7, and its sum(2)

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.*;

public class div1
{
    public static void main(String args[])
    {
        int sum=0,ct=0,n,i;
        try
        {
            DataInputStream s= new DataInputStream(System.in);
            System.out.println("Enter the limit :");
            n=Integer.parseInt(s.readLine());
            System.out.println("Numbers divisible by 7 are :");
            for(i=0;i<n;i++)
            {
                if(i%7==0)
                {
                    System.out.println(i);
                    ct++;
                    sum=sum+i;
                }
            }
            System.out.println("Sum= "+sum);
            System.out.println("Total Numbers divisible by 7 is :"+ct);
        }
        catch(Exception e)
        {
        }
    }
}
=========================================================================
Output :


Enter the 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: