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

amathiaitishar
amathiaitishar
13,229 Points

It keeps asking me to reformat code and import java.util.* even though I did. Any thoughts on this challenge?

I am using Eclipse IDE and following all the challenge tasks but in the last one I am kinda stuck...It keeps asking to reformat the code and import java.util.; even though I have made the reformat and imported the java.util.;

Any thoughts on this??

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;
            System.out.println(numberWords);

        }
    }

}
results.txt
five
one
six
four
two
[six, seven, eight, nine]
[six, seven, eight, nine]
[six, seven, eight, nine]
[six, seven, eight, nine]

3 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,459 Points

Hello, what it is asking you to do is to refactor and use the smart imports, which will only import the utils that you need., ArrayList and Arrays

Also, you will want to use the commands craig used to order the correct numbers. (on windows it was control + shift + up arrow/down arrow)

Secondly, the System.out.print("Three") is missing, and you'll want to add that.

Next, go ahead and instead of commenting out each line individually highlight both pieces of the code that need to be commented and hold Control + shift and press / to comment out both of those lines in a multi line comment, instead of individually.

Lastly, just fix the for loop to count where your System.out's leave off ( 5-10, you'll need to hand key "ten" in)

It should look something like

List<String> numberWords = Arrays.asList("six", "seven", "eight", "nine", "ten");
        for (String numberWord : numberWords) {
            System.out.println(numberWord);

Thanks, let me know if this doesn't help.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hmmm...you really should be using IntelliJ, but couple of things....

Does the results.txt output look ordered to you? Do you see any problem? Looks like you might be outputting the wrong variable, and didn't move lines around properly.

IntelliJ will auto-expand that * import. Pretty sure Eclipse has something similar. (Try Organize Imports)

Seth Kroger
Seth Kroger
56,403 Points

The challenge wants you to rearrange and fix the code so it prints out the words "one" through "nine" in order. It also wants you to to fix the import by removing the wildcard import and importing the individual classes (through an IDE fix).