aspose file tools*
The moose likes Beginning Java and the fly likes Method Calling Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method Calling Problem" Watch "Method Calling Problem" New topic
Author

Method Calling Problem

chandan kuchipudi
Greenhorn

Joined: Jun 27, 2012
Posts: 12
[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

Joined: Apr 06, 2010
Posts: 4465
    
    8

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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
chandan kuchipudi
Greenhorn

Joined: Jun 27, 2012
Posts: 12
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.. ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method Calling Problem