• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Method Calling Problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.. ...
 
Everybody's invited. Except this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic