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 trialrohan reddy
Courses Plus Student 443 PointsCan Someone Help?
String[] sports = { "Basketball", "Baseball", "Tennis",}; String bestSports = sports[0]; int numberOfSports = sports.length; String lastSports = sports[2];
String[] sports = { "Basketball", "Baseball", "Tennis",};
String bestSports = sports[0];
int numberOfSports = sports.length;
String lastSports = sports[2];
2 Answers
Daniel Hartin
18,106 PointsHi 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
Derek Crosson
991 PointsI'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
991 PointsSorry, I didn't read the challenge... Your variable name should be bestSport not bestSports
rohan reddy
Courses Plus Student 443 PointsThanq Derek It Helped :)
rohan reddy
Courses Plus Student 443 Pointsrohan reddy
Courses Plus Student 443 PointsNo It Didnt Help :(