❮ Previous Next ❯

JAVA Array Introduction

 

// Java program to illustrate creating an array
// of integers,  puts some values in the array,
// and prints each value to standard output.

class ArraySample
{
    public static void main (String[] args)
    {        
      // declares an Array of integers.
      int[] arr;
         
      // allocating memory for 5 integers.
      arr = new int[5];
         
      // initialize the first elements of the array
      arr[0] = 10;
         
      // initialize the second elements of the array
      arr[1] = 20;
         
      //so on...
      arr[2] = 30;
      arr[3] = 40;
      arr[4] = 50;
         
      // accessing the elements of the specified array
      for (int i = 0; i < arr.length; i++)
         System.out.println("Element at index " + i +
                                      " : "+ arr[i]);         
    }
}

Output

Element at index 0 : 10
Element at index 1 : 20
Element at index 2 : 30
Element at index 3 : 40
Element at index 4 : 50

Limitations


❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved