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

I have completed the code for enhanced loop but I can't figure out what it means to include the newline.

I am not sure what to include in the brackets after System.out.printf("??") if that is what the error message is telling me which is: make sure you include the newline! I can't find anything on the video that explains it, enough. Thanks any help is appreciated. Paul

Programmers.java
public class Programmers {

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

    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 programmer=programmers[i];
      System.out.printf("Yukihiro Matsumoto,David Nolen,Grace Hopper,Linus Torvalds, You");
      }

  }

}

2 Answers

Steven Parker
Steven Parker
229,732 Points

Having no newline is only part of the issue. Even if you add one, what this code will print looks like this:

Choose a programmer:
Yukihiro Matsumoto,David Nolen,Grace Hopper,Linus Torvalds, You
Yukihiro Matsumoto,David Nolen,Grace Hopper,Linus Torvalds, You
Yukihiro Matsumoto,David Nolen,Grace Hopper,Linus Torvalds, You
Yukihiro Matsumoto,David Nolen,Grace Hopper,Linus Torvalds, You
Yukihiro Matsumoto,David Nolen,Grace Hopper,Linus Torvalds, You

So you still need to change the code to include the line numbers and print each name by itself. And you can get a newline by using println, or with the code "%n".

Thanks Steven I'll try your suggestions