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 trialJhoset Ceron
16,280 PointsI don't know what is wrong with my code after I run it, it is saying import java.util.*; suspect
import java.util.*;
public class Messy {
public static void main(String[] args) {
System.out.println("one");
System.out.println("two");
System.out.println("three");
System.out.println( "four");
System.out.println("five");
/*
* 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(numberWord);
}
}
}
import java.util.*;
public class Messy {
public static void main(String[] args) {
System.out.println("one");
System.out.println("two");
System.out.println("three");
System.out.println("four");
System.out.println("five");
/*
* 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(numberWord);
}
}
}
one
two
three
four
five
six
seven
eight
nine
4 Answers
Andrew Winkler
37,739 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 - List and Arrays. The java.util.* is not considered correct because it is not memory nor speed efficient.
Also, I'm not sure if you're there yet, but you need to 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.
Andrew Winkler
37,739 Pointsimport java.util.Arrays;
import java.util.List;
public class Messy {
public static void main(String[] args) {
System.out.println("one");
System.out.println("two");
System.out.println("three");
System.out.println("four");
System.out.println("five");
/*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", "ten");
for (String numberWord : numberWords) {
// Use the sout shortcut to write out numberWord;
System.out.println(numberWord);
}
}
}
What is the error code when you run this?
Andrew Winkler
37,739 Pointsimport java.util.Arrays;
import java.util.List;
public class Messy {
public static void main(String[] args) {
System.out.println("one");
System.out.println("two");
System.out.println("three");
System.out.println("four");
System.out.println("five");
/*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", "ten");
for (String numberWord : numberWords) {
// Use the sout shortcut to write out numberWord;
System.out.println(numberWord);
}
}
}
What is the error code when you run this?
Jhoset Ceron
16,280 PointsOh thanks it worked. I guess the problem was that instead of putting import java.util.List; I put import.java.ArrayList;
Andrew Winkler
37,739 PointsAwesome! Yeah, Arrays and List are both children of the java.util class. Think of it like a file structure family tree. java -> util -> list
In the future, you should use an IDE and use it's shortcuts to tell you which resources you need to import to facilitate your code. Not only will you dodge errors like this one, but it'll be much faster and simplify how much you need to memorize/know about the java resources library. That way you can focus more so on just code and creation.
Jhoset Ceron
16,280 PointsThanks man!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jhoset Ceron
16,280 PointsThanks man!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jhoset Ceron
16,280 PointsJhoset Ceron
16,280 Pointswhen I paste the code at the end of the challenge, it is still giving me a compiler error. when i run the code on eclipse it runs fine, i don't know why is not working here