Showing posts with label Adding Arrays Elements. Show all posts
Showing posts with label Adding Arrays Elements. Show all posts

Saturday, 19 July 2014

How to Add Arrays Element in Java

Structure of the Problem Requirements 


An Array Consist of Many Records on his Indexing. In this Problem we have an Array and we are going to Add its all Elements and generate its Sum. Remember here we have just five integers for adding and if you wish to add more Elements then Simply Increase the Size of Array from 5 to up to you .

Source Code 


import java.util.Scanner;
public class    Arraysadding {
public static void main(String[] args) {
  
  
  Scanner input = new Scanner (System.in);
  int num[]  = new int [5];
  int num2[] = new int [5];
  int count =0;
   System.out.println("Enter Array Integer");
           for (int i= 0; i < 5;i++ )
           {
          
          num[i]=input.nextInt();
           count = num[i]+count;
           }
           System.out.println("Sum of Array is "+count);
 }

}

Output of the Program

Java Array Programming
Add Elements in Array