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

If you saw my last post 20 minutes ago, ignore it and read this one..need help

Hi, I'm not sure what this challenge is asking. I know it's pretty simple but could you read it and help out with some code? Thanks guys!

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
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;
        }
    }
}

1 Answer

Kevin Faust
Kevin Faust
15,353 Points

Hey Gabriel,

I wrote some notes in the code below to guide you what you have to do. And then I posted the solution at the bottom. Essentially what this challenge is doing is to make sure you know all the ide shortcuts and stuff that you learned in the video. You could very easily cheat yourself and just use your mouse to fix up the code but the point of it is to make sure you know how to use the shortcuts

import java.util.*;

public class Messy {
    public static void main(String[] args) {
        System.out.println("five");  //print out these 6 things in order. use the shortcut to rearrage their order
        System.out.println("one");
        System.out.println("six"); // System.out.println("three"); is missing. add that 
        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*/ 

//youve already got the above^ commented out which is great

        List<String> numberWords = Arrays.asList("six", "seven", "eight", "nine"); 

        // ^ since we already have "six" in our list, we can delete the above "six" using a shortcut
        // so basically just delete this line "System.out.println("six");" using the shortcut

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

//"use the sout" shortcut. do you remember what this is? use that shortcut to list out the string numbers one to nine

        }
    }
}

Answer code+the shortcuts (these shortcuts are for windows so for mac would be different)

import java.util.*;

public class Main {
    public static void main(String[] args) {
        System.out.println("one"); //use ctrl-shift+arrow keys to move a line up or down
        System.out.println("two");
        System.out.println("three");
        System.out.println("four");
        System.out.println("five");  
        System.out.println("six");  //use ctrl-y to delete this line
        /*Please comment out this line and
       this line as well with a hotkey that does multi-line commenting*/ //shift-ctrl-/
        List<String> numberWords = Arrays.asList("six", "seven", "eight", "nine");
        for (String numberWord : numberWords) {
            System.out.println(numberWord);
//             Use the sout shortcut to write out numberWord; 
//type in sout into the ide, select the first option. Bam! System.out.println should be automatically written
        }
    }
}

I hope that helped and I hope you understand what you have to do!

If this helped dont forget to mark as best answer so others can see

Happy coding and best of luck,

Kevin

Thanks Kevin. Just got it.