Asked by DeaconDuck2041

# Question 1: ArraySum 1a) Method to transform a number of an array...

Question 1: ArraySum

1a) Method to transform a number of an array

Use a method that receives two numbers with the same number of digits. It should transform each

number into an array of integers that represent the given number such that each element is a digit in the

array. example: given number:

1234 -> [1, 2, 3, 4]

In ArraySum.java implement this functionality inside the transform method.

int[] transform(int num)

1b) Method to compute the sum of two arrays that represent a very big number.

Assume you have two arrays of integers that represent two very big numbers as explained above and

shown as follows:

At this step, we should transform the two big numbers into two arrays.

First:

transform(1234) -> a which is [1, 2, 3, 4]

transform(1211) -> b which is [1, 2, 1, 1]

We know that a and b represent 1234 and 1211 respectively.

Now, complete the following method in ArraySum class that computes the sum of two given arrays.

Note: You are not allowed to transform the arrays into integers and then compute the sum since the

numbers will be very large numbers and you cannot store them into simple primitive data types.

Hint: In math, we always start from the last digit in the right (index i). In the case of having a carry, we

should include it in the sum calculation of the next digits (index i - 1). int[] sum(int[] a, int[] b)

Test case 1:

a -> [1, 2, 3, 4]

b -> [1, 2, 1, 1]

sum(a, b) -> sum([2,4,4,5], [1, 2, 1, 1])

Test case 2:

a -> [1, 2, 3, 4]

b -> [9, 2, 9, 5]

Page 5

sum(a, b) -> [1,0,5,2,9]

Note: You are not allowed to use ArrayList or other data structures that we have not covered in the class

in order to solve this question.

Answered by devsirji

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer`risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. L`

acinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur lao

, consectetur adipiscing elit. Nam l

gue

gue

iscing elit. Nam**cing elit. Nam lacinia pulvinar tortor nec facilisis.**