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

Showing posts with label core java:if. Show all posts
Showing posts with label core java:if. Show all posts

Friday, August 17, 2012

CJ-19:Sorting array numbers in ascending order

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 ascending 
{
    public static void main(String args[])throws Exception
    {
        DataInputStream din=new DataInputStream(System.in);
        int t,i,j;
        int n=0;
        int result=0;
        int a[]=new int[10];
        System.out.println("Enter the limit :");
        n=Integer.parseInt(din.readLine());
        System.out.println("Enter the numbers :");
        for(i=0;i<n;i++)
        {
            a[i]=Integer.parseInt(din.readLine());
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(a[i]<a[j])
                {
                    t=a[i];
                    a[i]=a[j];
                    a[j]=t;
                }
            }
        }
        System.out.println("The numbers in ascending orer is :");
        for(i=0;i<n;i++)
            System.out.println(a[i]);   
    }   
}
=========================================================================
Output : 
Enter the limit :
3
Enter the numbers :
5
7
2
The numbers in ascending order is :
2
5
7



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


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