Single dimensional array

Single dimensional array

A one dimensional or single dimensional array represents a row or column of elements.

Syntax to declare an single dimensional array
dataType[] arr; (or)
dataType []arr; (or)
dataType arr[];

Instantiation of an array
arrayname=new datatype[size];

Program of single dimension array
class test
{
public static void main(String args[])
{
int a[]={1,2,3,4,5};
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}

Output:
2
3
4
5

Program of passing array to method
class test
{
static void min(int a[])
{
int min=a[0];
for(int i=1;i<a.length;i++)
if(min>a[i])
min=a[i];
System.out.println(min);
}
public static void main(String args[])
{
int a[]={33,3,4,5,1};
min(a);
}
}

Output:
1

Leave a Reply

Your email address will not be published. Required fields are marked *