1
+ import java .util .Scanner ;
2
+ public class Assignment8_2 {
3
+ public static void main (String [] args ) {
4
+ Scanner scan = new Scanner (System .in );
5
+ System .out .println ("Enter the array length:" );
6
+ int len =scan .nextInt ();
7
+ int arr1 [] = new int [len ];
8
+ int arr2 [] = new int [len ];
9
+
10
+ // Taking the input for arr1
11
+ System .out .println ("Enter the arr1 elements:" );
12
+ for (int i = 0 ; i <= arr1 .length -1 ; i ++) {
13
+ System .out .println ("Enter an element" );
14
+ arr1 [i ] = scan .nextInt ();
15
+ }
16
+
17
+ // Taking the input for arr2
18
+ System .out .println ("Enter the arr2 elements:" );
19
+ for (int i = 0 ; i <= arr2 .length -1 ; i ++) {
20
+ System .out .println ("Enter an element" );
21
+ arr2 [i ] = scan .nextInt ();
22
+ }
23
+
24
+ // Creating the result array
25
+ int result [] = new int [len ];
26
+ int j =len -1 ;
27
+ // Adding the arr1 and arr2 elements and storing it in result array in reverse order
28
+ for (int i = 0 ; i <= arr1 .length -1 ; i ++) {
29
+ result [j ] = arr1 [i ]+arr2 [i ];
30
+ j --;
31
+ }
32
+
33
+ // Displaying the contents of the result array
34
+ System .out .println ();
35
+ System .out .println ("Result array contents are" );
36
+ for (int i = 0 ; i <= result .length -1 ; i ++) {
37
+ System .out .print (result [i ] + " " );
38
+ }
39
+ }
40
+ }
0 commit comments