Java simple program of defining array

      No Comments on Java simple program of defining array

Defining Array

This program illustrate the concept of defining array in java.

  • Array store the elements in contiguous memory location.
  • It can store a fixed-size sequential collection of elements of the same type.
  • The array size must be a integer type and it should be greater than 0.
  • In array the lowest address indicate the first element and the highest address indicate the last element.
  • Syntax to define array in java is “datatype arrayname[]=new datatype[size]”.
  • eg int x[]=new int[100].
  • Picture repersentation of array
  • defining array in java

class scan
{
public static void main(String arg[])
 { 
  int i;
  int x[]=new int[4];
  x[0]=1;
  x[1]=2;
  x[2]=3;
  x[3]=4;
 
 for(i=0;i<=3;i++)
  {
    System.out.println(x[i]);
  }
 }
}

OUTPUT:-

defining Array


Comment below if you are facing any problem


Java Program to Enter Elements of your choice in Array
Java Program to find Greatest Element in array
Java Program to print an alternate elements from an array


Summary
Java simple program of defining array
Article Name
Java simple program of defining array
Description
This program illustrate the concept of defining array in java.It can store a fixed-size sequential collection of elements of the same type.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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