This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method Calling Problem" Watch "Method Calling Problem" New topic

Method Calling Problem

chandan kuchipudi

Joined: Jun 27, 2012
Posts: 12
[Added code tags and formatted - please see UseCodeTags]

it is saying that : error: <identifier> expected
System.out.println("please enter two numbers ");
^ 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

Joined: Apr 06, 2010
Posts: 4541

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

Joined: Jan 28, 2003
Posts: 4181

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

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:
subject: Method Calling Problem
It's not a secret anymore!