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 trialSUDIPTA BOSE
201 Pointsshowing errror..can't find the mistake
compiler is showing errror.i checked it ten times but can't find the mistake.
public class Name{
public static void main(String[]args){
Console console=System.console();
String firstName="Sudipta";
console.printf("hello,my name is %s\n",firstName);
}
}
8 Answers
Chris Tvedt
3,795 PointsThere are 2 errors here. First one is the "console.readline. Remember camelcase. its supposed to be "console.readLine" Second one is "Console.printf" printf is not a static method in "Console", it is a method in you "console" object. So you need a lowercase "C" in console, not a capital one.
import java.io.Console;
public class Name {
public static void main(String[] args) {
Console console = System.console();
//"console.readLine()" NOT "console.readline()". Remember camelCase.
String firstName = console.readLine("What is your name? ");
//"console.printf()" NOT "Console.printf()". printf is not a static method.
console.printf("Hello, my name is %s\n", firstName);
}
}
Hope this helps you out.
Chris Tvedt
3,795 PointsOk, i have reviewed that challenge and i see that you have gone a little overboard. Read the simple instructions and to the challenge task by task:
First: "Make a String variable named "firstName" and set it equal to your name:
String firstName = "Sudipta";
Second: use the "printf" method on your console object to print "<YOUR NAME> can code in Java!"
//the console object has already been made, the comment on top of Name.java say so. So it is ready to be used.
console.printf("%s can code in Java!", firstName);
//This will also pass the third task.
Read the challenges and do them one step at the time :-)
SUDIPTA BOSE
201 Pointsthanks for the help Chris Tvedt
Matthias Nรถrr
8,614 PointsHello. Try to add
import java.io.Console;
at the top of your code. In the future could you please include the error the console is showing?
SUDIPTA BOSE
201 PointsI did it but still showing errors.
Chris Tvedt
3,795 PointsWhats ut error message? You sure you imported the java.io.Console library? Please show the whole code and the error you get.
SUDIPTA BOSE
201 PointsJavaTester.java:126: error: illegal start of expression import java.io.Console; ^ JavaTester.java:126: error: not a statement import java.io.Console;
JavaTester.java:128: error: illegal start of expression public class Name { ^ 3 errors
Chris Tvedt
3,795 PointsThe errors are at line 126 and 127. Are you doing this in a new java-file or trying to add it to an existing one? The java-filename must be the same as the class that the main method is in. Also, all imports MUST be at the top of the file. Are you doing this in IntelliJ IDE or workspaces?
SUDIPTA BOSE
201 Pointsactually it's a challenge
SUDIPTA BOSE
201 Pointsi understand now..i just have to write the particular code what they are asking,not full program.
SUDIPTA BOSE
201 PointsSUDIPTA BOSE
201 Pointsthanks.
SUDIPTA BOSE
201 PointsSUDIPTA BOSE
201 Pointsstill it is showing.i also copy paste above program but still it is showing error.
Chris Tvedt
3,795 PointsChris Tvedt
3,795 PointsWhat are your errors? Please post your errors here on the forum.