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 Arrays Iteration Looping Like These Programmers

What do i do wrong?

I have massege : Bummer I expected the last to be you but i get "".My name is last as privew shows.

Programmers.java
public class Programmers {

  public void printMenu() {
    String[] programmers = {
            "Yukihiro Matsumoto",
            "David Nolen",
            "Grace Hopper",
            "Linus Torvalds",
            "Bogdan Siverchuk"
    };

    System.out.println("Choose a programmer:");
    // TODO: Print out a menu by looping through the programmers array.
    /*
      The menu should be in the form of (each on a line of its own, starting with 1):
      1. Yukihiro Matsumoto
      2. David Nolen
      ...
    */
    for (int i=0; i < programmers.length; i++){
      String pro = programmers[i];
        System.out.printf("%n %d. %s %n ", i+1, pro);
    }

  }

}

4 Answers

Hi Steve! I did it without String pro = programmers[i] ; ....,programmers[i](and this too) I had the same problem, so i did this line in code and it didn't work as well.

Odd - it passed the challenge for me!

But the reason your code wasn't quite working was to do with the double %n and the extra spaces in the menu. The code output was pretty much correct but the challenge is very specific as to what it wanted to see.

Hi Bogdan,

It's a formatting issue - the output isn't quite what the challenge was expecting.

Your slightly amended code:

    for (int i = 0; i < programmers.length; i++){
      String pro = programmers[i];
        System.out.printf("%d. %s%n", i+1, pro);
    }

This works fine.

Steve.

P.S. My solution was basically the same.

    for(int i = 0; i < programmers.length; i++){
      System.out.printf("%d. %s%n", i + 1, programmers[i]);
    }

I'll retry ofc maybe internet had problems or something.

The code challenges do have problems every now and again.

yeah, the problem was with that space and extra %n. Thx mate!