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 trialamathiaitishar
13,229 PointsIt 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??
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);
}
}
}
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
Full Stack JavaScript Techdegree Graduate 35,467 PointsHello, 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
Treehouse TeacherHmmm...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)
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsBeat me by a minute.
Seth Kroger
56,414 PointsThe 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).