0% found this document useful (0 votes)
323 views3 pages

Array Programs

The document contains Java programs that demonstrate the declaration, instantiation, initialization, and traversal of arrays. It covers one-dimensional, two-dimensional, and multidimensional arrays, including user input for array elements. Each program illustrates how to handle arrays in Java using loops for input and output.

Uploaded by

nayankokane62
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
323 views3 pages

Array Programs

The document contains Java programs that demonstrate the declaration, instantiation, initialization, and traversal of arrays. It covers one-dimensional, two-dimensional, and multidimensional arrays, including user input for array elements. Each program illustrates how to handle arrays in Java using loops for input and output.

Uploaded by

nayankokane62
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

//Java Program to illustrate how to declare, instantiate, initialize and traverse the
Java array.
class ArrayDemo
{
public static void main(String args[])
{
int a[]=new int[5]; //declaration and instantiation
a[0]=100; //initialization
a[1]=200;
a[2]=300;
a[3]=400;
a[4]=500;
//traversing array
for(int i=0;i<[Link];i++)
[Link](a[i]);
}
}

2. //Java Program to illustrate one dimensional array

import [Link].*;
class OneDArray {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int a[]=new int[5];
[Link]("Enter numbers for array:");
for(int i=0;i<5;i++)
{
a[i]=[Link]();
}
for(int i=0;i<5;i++)
{
[Link](a[i]);
}
}
}

3. //Java Program to illustrate two dimensional array


import [Link].*;
class TwoDArray {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int a[][]=new int[3][2];
[Link]("Enter numbers for array:");
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
a[i][j]=[Link]();
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
[Link](a[i][j]);
}
}
}
}

4. //Java Program to illustrate multidimensional array


import [Link].*;
class MultiDArray {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int a[][][]=new int[3][2][2];
[Link]("Enter numbers for array:");
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
a[i][j][k]=[Link]();
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
[Link](a[i][j][k]);
}
}
}
}
}

You might also like