Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Eric Tang
Courses Plus Student 1,300 Pointserror '{' is expected
Hi , im trying to a code to prompt the users and get an answer in return but it keeps showing error . Could any of you check to see whats wrong.
import java.util.*; public class Introductions() { public static void main(Strings [] args) { Scanner keyboard = new Scanner(System.in); System.out.println("What is you name?"); String name = keyboard.nextLine(); System.out.println("Your name is %s",name);
}
}
6 Answers

kalyada leosrisook
Courses Plus Student 17,855 PointsYou can't use formatter '%s' with println. You gotta use it with System.out.printf.

Eric Tang
Courses Plus Student 1,300 PointsHi kalyada,
Thx for the quick reply . I've tried to change it from println to printf but that doens't seem to be the problem as it still says the same thing. It says error: '{' expected and has an arrow pointing to the parenthesis next to the class name Introductions

kalyada leosrisook
Courses Plus Student 17,855 Pointsoh, I see the problem now. You are not suppose to add any '()' on the class name. Just let the class name be
public class Introduction { //code here. } :)

Eric Tang
Courses Plus Student 1,300 PointsI deleted the parenthesis and now it says error: cannot find symbo

kalyada leosrisook
Courses Plus Student 17,855 PointsOkay, sorry, the code you posted was pretty hard to read so I've missed some of the mistakes. another mistake I just saw is : 'public static void main (Strings [] args)' you added 's' after the String .. the compiler doesn't recognise 'Strings'.

Eric Tang
Courses Plus Student 1,300 PointsYea sorry about that. I dont really know how to post it properly so i just copy and paste. I've tried to remove s after string but it still says expected '{' . How do i post the code properly, maybe then you could see clearly what the problem is

kalyada leosrisook
Courses Plus Student 17,855 Pointsdid it say which line the error is in? when I wrote you code in my IDE (the fixed version) it works fine.
import java.util.*;
public class Introductions
{
public static void main(String [] args)
{
Scanner keyboard=new Scanner(System.in);
System.out.println("What is you name?");
String name=keyboard.nextLine();
System.out.printf("Your name is %s",name);
}
}
ps. you use this symbol (```) before and after your codes . you can read more in the "Markdown Cheatsheet" below the comment.. :)

Eric Tang
Courses Plus Student 1,300 PointsIt still the class name line. Hmmm, could it be because I am using the workshop?

Eric Tang
Courses Plus Student 1,300 PointsGreat news. It works now.... Thats really strange. Don't really know what happened, but thx so much kalyada. You've helped heaps. :)

kalyada leosrisook
Courses Plus Student 17,855 PointsNo worries. It could be because you forget to save the file after making changes to it? xD It happens a lot to me haha