Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error displayed at println statement.

 
Joy Vergis
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i am new to java. I writing a program in eclipse. I get error at the println statement.

Program:

package package1;

public class ClassA {
String str1="a-b";

int a= str1.length(); //error at this line.

System.out.println();
}

Error displayed in eclipse:
Syntax error on token "println", Identifier expected after this token.

Please help
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't have code outside a method. you can declare variables, but you can't call methods or really 'do' stuff.
 
Pankaj Rathod
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you are calling System.out.println() without any argument.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could start with the almost-obligatory "HelloWorld.java" program that teaches basic program structure and the elements required. You can find a tutorial using an appropriate Google search that either shows how to create and run the program using a basic text editor at the command line (recommended) or using Eclipse. If you've decided on Eclipse as your IDE, construct and run the HelloWorld program using both the command line and IDE approaches so that you see what Eclipse does for you and have an idea what you'll have to do without Eclipse.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50216
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pankaj Rathod wrote:Also you are calling System.out.println() without any argument.
What's wrong with that? Look in the documentation and see whether it is permissible.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50216
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Eclipse or other IDEs at this stage.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic