• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Am a beginner - Function is not returning the value - everything seems to be fine

 
ganapathy ramadass
Greenhorn
Posts: 4
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


output error:


 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ganapathy,
Welcome to CodeRanch..

First of all, we would like you know some important things before you start using CodeRanch..
I would suggest you to see this link -> How To Ask Questions At JavaRanch..

Now, as for your problem, I can see that your method declaration is not correct, plus there are some more problems with your code..
You can visit JavaBeginnersFAQ for some important links that can help you..

Here's is a general class with two methods: -
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have defined the nooftimes() method, lines 6 to 9, inside your main() method.

In Java you cannot define methods inside methods. Move lines 6-9 outside the main() method. You'll also need to make the nooftimes() method static.
 
ganapathy ramadass
Greenhorn
Posts: 4
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:You have defined the nooftimes() method, lines 6 to 9, inside your main() method.

In Java you cannot define methods inside methods. Move lines 6-9 outside the main() method. You'll also need to make the nooftimes() method static.



thank you now i understand it clearly
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch indeed!
I've edited your post to make it the code more readable, as you may have noticed. You can do this yourself easily, all you have to do is UseCodeTags when you post a code snippet and the forum will add syntax highlighting and line numbers. Also a quick tip: if you want to copy text from the command-line output in Windows, all you have to do is right-click in the CMD window, choose mark from the menu, highlight the text you want to copy and hit enter. Then you can simply paste the text here. It saves you the hassle of having to create and upload image files.
 
ganapathy ramadass
Greenhorn
Posts: 4
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:Welcome to JavaRanch indeed!
I've edited your post to make it the code more readable, as you may have noticed. You can do this yourself easily, all you have to do is UseCodeTags when you post a code snippet and the forum will add syntax highlighting and line numbers. Also a quick tip: if you want to copy text from the command-line output in Windows, all you have to do is right-click in the CMD window, choose mark from the menu, highlight the text you want to copy and hit enter. Then you can simply paste the text here. It saves you the hassle of having to create and upload image files.


yaa here after i follow this
 
ganapathy ramadass
Greenhorn
Posts: 4
Android Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and the corrected code is....

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea of code tags is to show your indentation. Your code without indentation is very difficult to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic