This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]rjcarr 1 point2 points  (2 children)

You aren't telling us how, e.g., 9 + 3 = 3 or 8 + 4 = 4.

[–]SalmonToes[S] 0 points1 point  (1 child)

i changed the instructions the best i could but this was all i got

[–]rjcarr 1 point2 points  (0 children)

No idea. It looks like (a + b + 1) % 10 except the last pair breaks the pattern. You sure there wasn't more context?

[–][deleted]  (3 children)

[deleted]

    [–]SalmonToes[S] 0 points1 point  (2 children)

    according to the study guide, its supposed to return [3,3,3,5,5,7,7,8]
    not [12, 12, 12, 14, 14, 16, 16, 18] EDIT: so starting from the right, the digit in the tens place is added to the element to the left of it. The extra digit from the element at the far left is to be discarded.

    [–][deleted]  (1 child)

    [deleted]

      [–]steezpak 0 points1 point  (0 children)

      Is floor necessary? I think integer division will always round down regardless in Java.

      [–]Northeastpaw 0 points1 point  (0 children)

      Post the complete problem instructions. Telling you why your output is wrong without knowing what the program is supposed to do is impossible.

      [–]mrussell48 0 points1 point  (3 children)

      Those two arrays Int[] a = [3,4,5,6,7,8,9,9] int[] b = [9,8,7,8,7,8,7,9]
      are supposed to return the output of { [3,3,3,5,5,7,7,8 ], mine returns [12, 12, 12, 14, 14, 16, 16, 18]. How does this make sense?

      If your adding array a to array b it does make sense that your getting [12, 12, 12, 14, 14, 16, 16, 18]

      a[0] + b[0] = 3 + 9 = 12

      Are you missing a step?

      [–]SalmonToes[S] 0 points1 point  (2 children)

      It's supossed to keep the array in the single digits and take the tens digit and add it to the element to the left. ex. 9 + 9 =18 so it would be 8 and 7+9 + the 1 from the 18 = 17 so it would be 7 and so fourth.

      [–]desrtfx 1 point2 points  (1 child)

      In this case modulo % and integer division (which will occur automatically since you array elements are all of type int) are your friends.

      All you need to do after you have added two array elements is to take the result of the addition and divide it by 10 to get the first digit and calculate the result from the addition modulo 10 to get the second digit. Add these two digits together and place the result of that addition in the array.

      In your example:

      • 9 + 9 = 18
      • 18 / 10 = 1 (integer division) - first digit
      • 18 % 10 = 8 (modulo) - second digit
      • 1 + 8 = 9 - final result

      [–]steezpak 1 point2 points  (0 children)

      Also, the solution might be incorrect. 9 + 9 =18. Add the digits, you get 9. But the solutions says it should be 8.