• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Calling Problem

 
chandan kuchipudi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Added code tags and formatted - please see UseCodeTags]


it is saying that :


Function.java:4: error: <identifier> expected
System.out.println("please enter two numbers ");
^
Function.java:4: error: illegal start of type
System.out.println("please enter two numbers ");
^
2 errors




please check the code and help me ...thank you ..
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Executable statements need to be in a method, not directly in the class body. That error is because it's trying to interpret line 4 as a declaration, but it isn't one.

Also, do you realise your sum(), mul() and sub() methods don't do anything? They declare a local variable, then do nothing with it.

I'd suggest revisiting your tutorial on what a class should look like.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't have executable code like 'System.out.println(...)' at the class' top level - it must be in a method. The top level of the class should be for class member definition and initialization only. You should move the System.out line, and the two calls to sc.nextInt() into a method body.
 
chandan kuchipudi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your concerns ....i'll try to read my class notes once before proceeding to coding ...and working with Scanner class is not a good idea for a beginner i think .. ...1.var.initalization ,2.cmd line arguments ...then only scanner class to read inputs from keyboard.. ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic