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

Declare a String variable named bestSport and initialize it to the first element of the sports array.

Declare a String variable named bestSport and initialize it to the first element of the sports array.

Array.java
String[] sports = { "Basketball", "Baseball", "Tennis" };
String[] BestSports = {"football"};

2 Answers

We access array using the number of the element which always begins at zero. Recall the video and how you access an individual element in an array:

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

// Access an element in the array

// Basketball
sports[0]; 
// Baseball
sports[1];
// Tennis
sports[2];

So for our challenge:

Declare a String variable named bestSport:

String bestSport;

initialize it to the first element of the sports array.

String bestSport = sports[0];

stil its giving me a syntax error

Please paste your complete code. I tested the code I wrote and it works as expected.