Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

import java.util.

Scanner;
public class ArrayAddition
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter the size of the two arrays");
int size = scan.nextInt();
int [] array1 = new int[size];
int [] array2 = new int[size];
int [] result = new int[size];

System.out.println("Enter the elements of array 1");

for (int i = 0; i < size; i++)


{
array1[i] = scan.nextInt(); }

System.out.println("Enter the elements of array 2");

for (int i = 0; i < size; i++)


{
array2[i] = scan.nextInt();
}

for (int i = 0; i < size; i++)


{
result[i] = array1[i]+array2[i];}

System.out.println("Sum of elements of array1 and array2");


for (int i = 0; i < size; i++)
{
System.out.print(result[i]+" ");}
}
}

Output:
Enter the size of the two arrays
5
Enter the elements of array 1
10
20
30
0
0
Enter the elements of array 2

20
50
30
70
80
Sum of elements of array1 and array2
30 70 60 70 80

You might also like