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 (retired 2014) Learning the Language Introduction to Arrays

Declare a String variable named 'lastFrog' and initialize it with the third element of the frogNames array.

I'm stuck my mind has gone blank about the string variables can anybody help me please. ps I'm very new to java coding this is my first time going through the tutorials so any help would be much appreciated.

3 Answers

hey there lee, I'm very new to this as well and just got past that part this morning. he is my code and I will use the // comment convention to the right of each line to explain. I hope this is helpful to you; I know it helps me as a means of review. this is how I understand what I have learned so please take it for that rather than gospel. to the rest of the forum, please feel free to straighten me out if I am off course.

-adam

1.String[] frogNames = { /String is the type of variable (letters) that we are going to declare. [] indicates a range of possible string values. frogNames is how we will refer to this string moving forward in the code. The open curly bracket indicates the start of out list of values./

  1. "pat", //potential string value
  2. "rat", //potential string value
  3. "fat"}; //potential string value and a close curly bracket to indicate the end of the list.

  4. String bestFrog = frogNames [0]; /*String bestFrog is the declaration of a new variable. = sets the new string to the value to the right of it. the value frogNames[0] indicates the first name on out list of frog names in the first string we declared -String[]frogNames */

  5. int numberOfFrogs = (frogNames.length); /* int is another type of variable used to declare an integer, meaning a whole number. numberOfFrogs is the how we will refer to this integer going forward. = sets the value of numberOfFrogs to the value to its right. (frogNames.length) as a value means the number of values in the string frogNames which we declared at the top. in this example where there are 3 names in the list, pat, rat, and fat, our integer would be 2. and as ben said, 2 really means 3 because we are counting from zero, e.g. pat=0, rat=1, fat=2 */

  6. String lastFrog = frogNames [2]; /* here we are declaring a new string variable named lastFrog whose value is frogNames[2] which sets the value of this new string lastFrog to the value in the 2 position of list of names in the string variable frogNames which is the last position, the third name, fat. */

that is great thank you for the help. as soon as i read the answer it clicked so thanks again.

Daniel Cardenas
PLUS
Daniel Cardenas
Courses Plus Student 9,236 Points

Great post and explanation Adam. I'm considering taking my notes just how you posted these. Thanks again!

Thanks Daniel. I'm glad this helped people. reading back over it I see a bunch of typos and a couple of unclear items, but hey, I'm no teacher and I wouldn't take pay for my help; I'm just glad to help where I can.