Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements.

Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements.

1 Answer

The middle element being the second element in the array, being that arrays are 0 indexed the index of the middle element is 1. So to get the middle element out of the arrays you would do something like this. (assuming these are primitive arrays and not ArrayList or the like)

a[1]
b[1]

assign those two values to a new array and return it.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

thanks bruh