How to Add two Arrays in Java

Arrays are very Important in Programming . Arrays are used 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

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment