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
Damon Tunstall
2,327 PointsCoding challenge: Conditional ints Where am I going wrong? Is it to do with console??
Hey, I am struggling with this coding challenge. It is Task 2.
The task is:
Add an if statement to see if there are less than 4 people. Then write out to the console, “Your table is ready”
My code is:
import java.io.Console;
Console console = System.console();
int numberOfPeople = 3;
if (numberOfPeople < 4){
console.printf("Your table is ready");
}
My output is:
JavaTester.java:125: error: illegal start of expression import java.io.Console; ^ JavaTester.java:125: error: not a statement import java.io.Console; ^ 2 errors
Where am I going wrong?
1 Answer
andren
28,558 PointsThe console object is imported and instantiated for you automatically in most of these challenges, so importing and instantiating it again will cause an error.
If you remove the two first lines and just leave this code:
int numberOfPeople = 3;
if (numberOfPeople < 4){
console.printf("Your table is ready");
}
Then you should be able to successfully complete the challenge.
Damon Tunstall
2,327 PointsDamon Tunstall
2,327 PointsThis worked. Thank you :-)