Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Arrays Iteration Looping Like These Programmers

Paul Zutrau
Paul Zutrau
3,362 Points

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
216,812 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".

Paul Zutrau
Paul Zutrau
3,362 Points

Thanks Steven I'll try your suggestions