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 trialAbhishek Gangadhar
9,467 PointsDon't Understand why I'm getting an error here... I need to allot the value of the length of an array to an integer
String bestSport = "Crcket"; String[] sports = { bestSport, "Baseball", "Tennis" }; int numberOfSports;
numberOfSports=sports.lenght;
String bestSport = "Crcket";
String[] sports = { bestSport, "Baseball", "Tennis" };
int numberOfSports;
numberOfSports=sports.lenght;
1 Answer
Steve Hunter
57,712 PointsHi there,
Here's the code for that part of the challenge.
Firstly, when you are declaring a string variable and storing the first array element in it, that should be done by accessing the array. econdly for you int
variable, you need to declare it as such first (you can do this on one line), then use the length
property (check your spelling).
String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = sports[0];
int numberOfSports = sports.length;
I hope that helps.
Steve.
Abhishek Gangadhar
9,467 PointsAbhishek Gangadhar
9,467 PointsWow thanks lot Steve :) I'm amazed at hope fast i got help here :)
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHey, no problem! There's usually someone looking at the forum trying to help people out.
:-)
Steve.