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 Java Basics Getting Started with Java Strings, Variables, and Formatting

showing errror..can't find the mistake

compiler is showing errror.i checked it ten times but can't find the mistake.

Name.java
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
Chris Tvedt
3,795 Points

There 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.

thanks.

still it is showing.i also copy paste above program but still it is showing error.

Chris Tvedt
Chris Tvedt
3,795 Points

What are your errors? Please post your errors here on the forum.

Chris Tvedt
Chris Tvedt
3,795 Points

Ok, 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 :-)

thanks for the help Chris Tvedt

Matthias Nörr
Matthias Nörr
8,614 Points

Hello. 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?

I did it but still showing errors.

Chris Tvedt
Chris Tvedt
3,795 Points

Whats ut error message? You sure you imported the java.io.Console library? Please show the whole code and the error you get.

JavaTester.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
Chris Tvedt
3,795 Points

The 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?

actually it's a challenge

i understand now..i just have to write the particular code what they are asking,not full program.