The array taking one subscript is known as one-dimensional array.
The general form to declare an array is:
here type declares the element type of the array. The element type determines the data type of each element. For example, the following declares an array named silan will the type array of int :
here arr is an array(variable), but no array actually exists. That means the value of array is set to null which represents an array having no value. So java concept is saying that to link arr with an actual, physical array of integers, you must allocate using new operator(special operator for allocating memory) and assign it to arr. The general form of new for allocating one-dimensional array is :
type specifies the type of data being allocated.
when this statement is executed, 20(4bytes*5) of memory will be allocated dynamically named as arr having capability to contain maximum 5 integer data items.
When the values are assigned to an array is known as array initialization,
Let’s see a simple array program:
public static void main(String args)
int sum=0, size;
Scanner s=new Scanner(System.in);
System.out.println("enter the size of the array:");
int a=new int[size];
System.out.println("enter the elements the array elements:");
System.out.println("sum is: "+sum);
System.out.println("average is: "+avg);
enter the size of the array
enter the array elements
sum is 15
average is 3.0