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

Java Java Objects (Retired) Creating the MVP For Each Loop

Alexander Nowak
Alexander Nowak
498 Points

For each challenge

Hi

Think iv almost got it but could someone please pint out where I'm going wrong?

Thanks

I can't seem to attach my code. How do I do this?

Thanks

1 Answer

Matthew Alexander
Matthew Alexander
14,000 Points
public int getTileCount(char specialTile) {
   int count = 0;
    for (char tile: mHand.toCharArray()) {
      if (tile == specialTile) {
        count++;
      }
    }
    return count;
  }

A very good explanation that helped me is this one

Brett Connolly
Brett Connolly
12,874 Points

Took me forever to try and figure out before coming here. I'm new to Java so i'm still getting hung up on the way for-loops work compared to other languages and comparisons. This is a little different from the exercise we've been working in so the (tile == specialTile) which, in the exercise context would make more sense as (letter == tile), threw me off.