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

Android Build a Simple Android App (2014) Coding the Fun Facts Using an Array

Saurabh B
PLUS
Saurabh B
Courses Plus Student 2,880 Points

Did not understand

Please help me understand the meaning of the challenge question and also tell me its answer.

Array.java
String[] sports = {"Football","Basketball."};
int numberOfSports = sports.length;

1 Answer

Hi Saurabh,

The question is dealing with handling arrays and their elements. You start with an array given to you by the challenge:

String[] sports = { "Basketball", "Baseball", "Tennis" };

This is an array of Strings called sports that has three elements, as shown.

The first question asks you to create a variable called bestSport and assign the value of the first array element to it:

String bestSport = sports[0];

Arrays start counting at zero so the first element is found at [0].

Next up, you are asked to create an integer variable and assign the length of the array to it. You have done this correctly in your code above:

int numberOfSports = sports.length;

The last question is similar to the first in that it asks for a String variable called lastSport to have the last array element assigned to it:

String lastSport = sports[2];

In your code, you have amended the array and have also deleted the code from the first question. The challenge is probably expecting them to be left there. In full, the end solution looks like:

String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = sports[0];
int numberOfSports = sports.length;
String lastSport = sports[2];

I hope this helps!

Steve.

Hey, not a problem. That's what the forums are for - just keep asking questions when you run into problems!

Steve.