Posts

Showing posts from August, 2018

Another way to declare and intialize array elements

class ajit{    public static void main(String args[]) {      int a[]={33,3,4,5};//declaration, instantiation and initialization      //printing array   for(int i=0;i<a.length;i++)//length is the property of array   System.out.println(a[i]);      } }  Output:33        3        4        5

Declaration,initialisation and printing of array elements

class Testarray{   public static void main(String args[]){      int a[]=new int[5];//declaration and instantiation   a[0]=10;//initialization   a[1]=20;   a[2]=70;   a[3]=40;   a[4]=50;      //printing array   for(int i=0;i<a.length;i++)//length is the property of array   System.out.println(a[i]);      }}   Output: 10        20        70        40        50