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

Can Someone Help?

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

Array.java
String[] sports = { "Basketball", "Baseball", "Tennis",};
String bestSports = sports[0];
int numberOfSports = sports.length;
String lastSports = sports[2];

2 Answers

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Rohan

It looks as if you've simply put an extra comma inside your array, you should clear any compile errors after removing the last comma, on a separate note obtaining the last index of the array dynamically can be done by using the length -1 (demonstrated in the code below) which will help in real world situations.

String[] sports = { "Basketball", "Baseball", "Tennis"};
String bestSports = sports[0];
int numberOfSports = sports.length;
String lastSports = sports[(numberOfSports - 1)];

Hope this helps

Daniel

No It Didnt Help :(

Derek Crosson
Derek Crosson
991 Points

I'm not a Java programmer so this might not be correct but it's worth a try.

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

Derek Crosson
Derek Crosson
991 Points

Sorry, I didn't read the challenge... Your variable name should be bestSport not bestSports

Thanq Derek It Helped :)