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 Local Development Environments Exploring Your IDE Clean up this mess

LDE

Challenge Task 5 of 5

Now finally after running your code, please paste it in the Messy.java file and the results from the console in the results.txt tab.

Messy.java
import java.util.*;

public class Messy {
    public   static void main(String[]      args){
System.out.println("five");System.out.println("one");
    System.out.println("six");
    System.out.println( "four"       );     System.out.println("two");
    Please comment out this line and
    this line as well with a hotkey that does multi-line commenting
    List<String> numberWords = Arrays.asList("six", "seven", "eight", "nine");
    for (String numberWord:         numberWords) {
      // Use the sout shortcut to write out numberWord;
      }
    }}
results.txt
one
two
three
four
five
six
seven
eight
nine

1 Answer

Hi Princess,

There are gaps in your code that needs cleaning up. Did you run this through your IDE? The reformat code function should have cleaned some of this up for you.

At task 3 of 5, you needed to comment out the text that says:

    Please comment out this line and
    this line as well with a hotkey that does multi-line commenting

You can use the keyboard shortcut within the IDE to do that, or just do it yourself.

Lastly, you need to use the sout shortcut in the IDE to output the local variable in the for loop here:

    for (String numberWord:         numberWords) {
      // Use the sout shortcut to write out numberWord;
      }

The purpose of the challenge is to turn the code at the beginning of the challenge into something that is correctly formatted and spaced. So you need to delete extra spaces, make sure brackets are in the right place, indentation is correct. For example, these should be on two lines (and in a different order) and there is unnecessary space after the string "four".

System.out.println( "four"       );     System.out.println("two");

At the top of the class there are extra space again between public and `static. Indentation of the second line is wrong and the order of the numbers is wrong too. The second line should be spread over two lines of code as well.

public class Messy {
    public   static void main(String[]      args){
System.out.println("five");System.out.println("one");

So, clean up the code and reorder the lines so that the output is in numerical order. Make sure there's no extra spaces and indentation is correct too. Comment out the lines where it says to and use System.out.println to output inside the for loop.

Then you paste the output of the code into the challenge. The output you have pasted has not come from the code in this post but the output looks correct. Without outputting from the for loop, you aren't able to output six through nine.

I hope that helps,

Steve.