identifier expected
This error message is shown when the statements are not written in proper place. Most often, mistakenly, we may write the processing task (for example assigning value to a variable; writing a loop etc.) outside of any method. In this situation we may see this type of error message.
Then the solution is to write such statements inside the appropriate methods.
See the example code below:
Then the solution is to write such statements inside the appropriate methods.
See the example code below:
public class IdentifierExptectedSee the solution now:
{
int number1,number1,sum;
number1=10; // identifier expected
number2=20; // identifier expected
sum=number1+number2; // identifier expected
/*
The assignment statement must be written inside a method. Variables can also be assigned/ initialized during the declaration.
*/
public void display()
{
System.out.println("Number 1 = "+number1);
System.out.println("Number 2 = "+number2);
System.out.println("Sum = "+sum);
}
}
public class IdentifierExptectedSolved
{
int number1=10,number2=20,sum;
public void sum()
{
sum=number1+number2;
}
public void display()
{
System.out.println("Number 1 = "+number1);
System.out.println("Number 2 = "+number2);
System.out.println("Sum = "+sum);
}
}