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






Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment