Array program for declaring, initializing and using an array.


 Array Concept

  •  What is an 'array'?
Ans. Arrays are objects that can store multiple homogeneous (i.e. of same data type) data values at a time.


Array Program

Let us consider a small program to understand the topic in detail.


public class Array{

  public static void main(String ARGS[]){

    int[] array={10,20,30,40,50};    //more elements can be inserted

    //declares   //initializes

    int sum=0;

    for(int i=0;i<array.length;i++){

      sum=sum+array[i];

      //using the elements of  array for addition

    }
    //for output

    System.out.println("Sum of array's elements is "+sum);
    
    //for getting all the elements

    for(int i:array){

       System.out.println(i);

    }//this prints all the elements of the array
    
    }
}



Hope you have understood the Array concept now.

For more Program codes and videos visit my Youtube channel :

 https://youtube.com/channel/UC27TQ7zJKapHF78bwvi5iVw

For more Posts based on Programming visit my Blog:http://studytable10.blogspot.com/






Thanks!!   





Comments

Popular posts from this blog

You have accidentally left your suitcase behind when you got off the train. You only realized it after the train left the platform. Write a letter to the station master reporting your loss and request that the suitcase is located and kept till you claim it.

You went to an ATM to withdraw some money but the machine did not dispense cash. However, the amount got debited from your account. Write a letter to the manager of a bank, complaining about the deduction of money from your Savings Bank Account, while you did not receive the cash from the ATM, which you used to withdraw the money | Study Table

Shorthand Assignments Program for Java