#What does You have a syntax error in your code: Unexpected token '}' means?
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
In Java, the error message "You have a syntax error in your code: Unexpected token '}'" means that there is an issue with the placement or usage of a closing curly brace ('}').
This error typically occurs when there is an extra or missing closing curly brace in your code. Each opening curly brace ('{') should have a corresponding closing curly brace ('}') to define the scope of a block of code, such as a method, loop, or conditional statement.
To fix this error, you need to carefully review your code and ensure that all opening and closing curly braces are properly matched. Make sure that each opening brace has a corresponding closing brace and vice versa. Additionally, check for any misplaced or unnecessary braces.
Here's an example to illustrate the issue:
public class Example {
public static void main(String[] args) {
int x = 5;
if (x > 0) {
System.out.println("Positive number.");
} // Missing closing brace for if statement
} // Unexpected token '}' - extra closing brace
} // Unexpected token '}' - extra closing brace
In this example, there is a missing closing brace for the if statement and two extra closing braces at the end of the code. To fix it, you would need to add a closing brace after the System.out.println statement and remove the two extra braces at the end:
public class Example {
public static void main(String[] args) {
int x = 5;
if (x > 0) {
System.out.println("Positive number.");
}
}
}
By ensuring proper matching of opening and closing braces, you can resolve this syntax error.
idk
im new to programming
`public class Staircase extends SuperKarel
{
public void run()
{
putBall();
{
while(frontIsClear())
}
}
private void createStep()
{
turnRight();
putBall();
while (frontIsClear())
{
move();
putBall();
turnLeft();
}
}
}`
this is what i typed in
it was a mess and the indications for the excersice are just to ident
it should be formatted like this:
public class Staircase extends SuperKarel {
public void run() {
putBall();
// problem is here
{
while(frontIsClear())
}
}
private void createStep() {
turnRight();
putBall();
while (frontIsClear()) {
move();
putBall();
turnLeft();
}
}
}
and the problem that is telling you is your while loop and the { }
yeah ofc
sorry but I need to say:
thats quite a shit "course" or whatever that is
I wanted to ask for a propper identing info
idk if you got some video on yt or something to understand better
to better learn java?
we usually recommend "mooc's" java course
its by a finnish university and really great
I went through it myself to learn java
and it gives you certificates at the end (not really important though)
MOOC is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.
It consists of two parts, one at beginner, and another at intermediate level. The end of the course is marked by creating your own Asteroids game clone!
Even though the instructions show how to configure and use NetBeans for the course, you can use IntelliJ. To use IntelliJ, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.
Visit MOOC here: https://java-programming.mooc.fi/
(the course is available in both English and Finnish)
About the course - Java Programming
some more information about it
there is
but it tells you wrong formatting
the functionality problem its talking about is here:
public void run() {
putBall();
// problem is here
{
while(frontIsClear())
}
}
yea I realized it was wrong
maybe i should tell the teacher right?
D:
๐
- Open brace โ{โ appears at the end of the same line as the declaration statement
- Closing brace โ}โ starts a line by itself indented to match its corresponding opening
statement, except when it is a null statement the โ}โ should appear immediately after the
โ{โ
basically
public void method1() {
System.out.println("Hello World!");
}
and if its empty
public void method2() {}
no problem
ill write down all the info you provided
they should def. look up java style conventions
also maybe they got this wrong as well:
The naming convention in Java is as follows:
Classes:
PascalCase. Example: GoldMiner, FoodDestroyer, DispenserBuilder
Methods / Fields / Variables:
camelCase. Example: foodAmount, integerValue, goodBoyAsADog
Packages:
All lowercase. Preferably the domain name backwards. Example: "google.com" ==> com.google, "ialistannen.me" ==> me.ialistannen
Followed by the project name. Example: Project "Builder" ==> com.google.builder
Constants/Enum entries:
UPPER_SNAKE_CASE. Where words are separated by underscores. Example: RED_DOG, I_AM_THE_BEST, CONQUER_WORLD
conventions you should follow to make it easier for other devs to go through your code
sad that they teach it like this
so everyone new will just accept it and think it is right
IN FACT IT HAPPENED WITH ME LMAO
im abt to cry bc this is the next thing i have to do
come on now, help karel find the ball
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐