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!

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 (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