Sunday, May 17, 2009

Published 5/17/2009 by with 2 comments

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:
public class IdentifierExptected
{
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);
}


}

See the solution now:

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);
}



}
    email this       edit

2 comments:

  1. this is fascinating. i have joined your feed and stay up for in the hunt for more of your interesting post.

    www.n8fan.net

    ReplyDelete
  2. Diesel Generator on Rent

    https://palsvam.com/dg-genset-on-rent.php

    ReplyDelete