Share
Explore BrainMass

Java Program using Two Arrays of Undefined Length in Runtime

Write a program in Java which defines two unconstrained arrays of user defined length n, that contain n Random numbers each and which outputs the addition of pairs of elements. For example, given {1, 2, 3} and {4, 5, 6} the output would be {5, 7, 9}. Please use well commented code. The program must consist of at least 2 files.

Let's assume the user enters an array length of 5. The output would be:

arr1 arr2 sum
0 12 7 19
1 34 19 53
2 2 45 47
3 23 8 31
4 14 23 37

Solution Preview

I have attached the program which creates two arrays A and B using method populateArray() whose size is determined by user input. A and B are populated using method ...

Solution Summary

I have attached the program which creates two arrays A and B using method populateArray() whose size is determined by user input. A and B are populated using method populateArray() with random numbers of the given size n. Finally, the two arrays and their sum kept in another array C are displayed using method showArrays(). All of these methods are encapsulated in a class called Arrays . An instance of Arrays object in the main method of another class ArrayMain. Thus the program consists of two files Arrays.java and ArrayMain.java, both of which are included in the attached compressed file. Two compiled class files are also included.

$2.19