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-18 : Store n numbers into an Array and print it

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 array 
{
   public static void main(String args[]) 
    {
        int a[]=new int[20];
        int i,n;
        try
        {
            DataInputStream x=new DataInputStream(System.in);
            System.out.println("Enter limit value for array");
            n=Integer.parseInt(x.readLine());
            System.out.println("Enter array elements :");
            for(i=0;i<n;i++)
            {
                a[i]=Integer.parseInt(x.readLine());
            }
            System.out.println("array elements are :");
            for(i=0;i<n;i++)
            {
                System.out.println(a[i]);
            }
        }
        catch(Exception e)
        {
        }
    }      
}    
=========================================================================
Output : 

Enter limit value for array
5
Enter array elements :
1
2
3
4
5
array elements are :
1
2
3
4
5

No comments: