Saturday 19 July 2014

How to Add two Arrays in Java

Structure of the Problem Requirements 

Arrays are very Important in Programming . Arrays are use to store large amount of data with different style and with different indexing. In this Problem we have three Array of Integers . First two Arrays contains integers and the third one Array consist of their Addition.

Source Code 

import java.util.Scanner;
public class ArraysAddition {
public static void main(String[] args) {
  Scanner input = new Scanner (System.in);
  int num[]  = new int [5];
  int num2[] = new int [5];
  int sum[] = new int [5];
  System.out.println("Enter Integer for 1st Array");
   for (int i= 0; i < 5;i++ )
       {num[i]=input.nextInt();}
         System.out.println("Enter Integer for 2nd Array");
         for (int k=0;k<5;k++)
         {num2[k]=input.nextInt();  }
         System.out.println("Sum of both Arrays is");
         for (int s=0;s<5;s++)
         {sum[s]=num[s]+num2[s];
        System.out.println(sum[s]);
         }
  }}

Output of the Program


Java Array Programming
Adding Two Arrays






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