Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (retired 2014) Learning the Language Introduction to Arrays

Kevin Lombardi
Kevin Lombardi
2,977 Points

Declaring and integer

The instructions are to declare an integer numberOfFrogs and to then set it to the number of elements in the array using the length property. I cannot figure this one out. I've tried rewatching the video multiple times.

3 Answers

Lets break this and see

  • first declare an integer variable called numberOfFrogs

  • Next if you watch the video carefully the use of length property has been shown. It gives you the number of elements inside the array. So in case of frogNames that would be 3 i.e. He, Be and Te

  • Now the value of 3 will be assigned to the integer variable numberOfFrogs using the length property of arrays

String [] frogNames = {"He", "Be", "Te"};
String bestFrog = frogNames[0];
int numberOfFrogs = frogNames.length;

Hope that helps.

Kevin Lombardi
Kevin Lombardi
2,977 Points

Thanks! I thought I did that but I probably had a typo in my syntax. Thanks for your assistance.

Kevin Lombardi
Kevin Lombardi
2,977 Points

It worked. I don't know what I was doing. Thank you again.

Great! You'r welcome