Author

Author- Ram Ranjeet Kumar

Friday, July 26, 2019

Program to add two array in Java

import java.util.*;
class AddArray
{
public static void main(String[] args)
{
int array1[]=new int[100];
int array2[]= new int[100];
int array3[]=new int[100];
int i,j,n;
Scanner sc=new Scanner(System.in);
System.out.println("\n\t\tProgram To Add Two Array.!");
System.out.print("\n\t\tEnter the Default size Of two Array==> ");
n=sc.nextInt();
System.out.println("Enter the " +(n+1)+" element in first Array array1");
for(i=0;i<=n;i++)
{
System.out.print("\n\t\tarray1["+i+"]= ");
array1[i]=sc.nextInt();
}

System.out.println("Enter the " +(n+1)+" element in second Array array2");
for(i=0;i<=n;i++)
{
System.out.print("\n\t\tarray2["+i+"]= ");
array2[i]=sc.nextInt();
}
System.out.println("\n\t\tElements in Array1 .!");
for(i=0;i<=n;i++)
{
System.out.print("\n\t\tarray1["+i+"]= "+array1[i]);
}
System.out.println("\n\t\tElements in Array2 .!");
for(i=0;i<=n;i++)
{
System.out.print("\n\t\tarray2["+i+"]= "+array2[i]);
}
System.out.print("\n\t\tAddition Of Array1 and Array2");
for(i=0;i<=n;i++)
{
array3[i]=array1[i]+array2[i];
System.out.println("\n\n\t\tArray1["+i+"]+Array2["+i+"]==>("+array1[i]+"+"+array2[i]+")=Array3["+i+"]= "+array3[i]);
}
}
}
OUTPUT

No comments:

Post a Comment