This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 4
Android Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


output error:


 
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: -
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and the corrected code is....

 
Marshal
Posts: 76856
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The idea of code tags is to show your indentation. Your code without indentation is very difficult to read.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic