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
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 :
7
14
21
28
35
42
49
Sum= 196
Total Numbers divisible by 7 is :8
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 :
50Numbers divisible by 7 are :
07
14
21
28
35
42
49
Sum= 196
Total Numbers divisible by 7 is :8
No comments:
Post a Comment