5. Arrays
Arrays is basically a container whhich can store a values (or) sequence of numbers,values,character itself.
Each item is an array is called an element is accessed by its numerical index.As shown in the preceeding illlustration,always numbering begins with zero.
Let see an example:
package test package;
public class Array Demo
{
public static void main(string [] args )
{
// declares an array of integers
int [] an Array;
// allocates memory for 10 integers
an Array = new int [10];
// initialise first element
an Array [0] = 100;
initialise second element
an Array [1] = 200;
// and so forth
an Array [2] = 300;
an Array [3] = 400;
an Array [4] = 500;
an Array [5] = 600;
an Array [6] = 700;
an Array [7] = 800;
an Array [8] = 900;
an Array [9] = 1000;
sytem.out.println("Element at index 0 :" + anArray [0] 0;
system.out.println("Element at index 1 :" + anArray [1] );
system.out.println("Element at index 2:" = anArray [2] );
system.out.println("Element at index 3:" + anArray [3] );
system.ou.println("Element at index 4:" + anArray [4] );
system.out.println("Element at index 5:" + anArray [5] );
system.ou.println("Element at index 6:" + anArray [6] 0;
system.out.println("Element at index 7:" + anArray [7] );
system.out.println("Element at index 8:" + anArray [8] );
system.out.println("Element at index 9:" + anArray [9] );
system.out.println("Element at index 10:" = anArray [10] );
}
}
Output:
Element at index 0 : 100
Element at index 1 : 200
Element at index 3 : 300
Element at index 4 : 500
Element at index 5 : 600
Element at index 6 : 700
Element at index 7 : 800
Element at index 8 : 900
Element at index 9 : 1000
2 Comments
Easily to understand
ReplyDelete😲 wow
ReplyDeleteIt's good