Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error

 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have a question about the following code. I keep getting errors about the "static double findCharge(int Kwh)" line. Does something need to be before that to make it compile like public static int( ) ??? Help anyone?

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Holly,

You've "nested" the definition of findCharge() inside your main() method, and that's not allowed. Method definitions all have to be at the "top level" of a class, enclosed only by the class X {...} set of braces.
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So do I just move the static double part of the code or the whole while loop? Sorry I am sure that is a dumb question
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to move the method "static double part of the code" out of the while loop. In the while loop it looks like you'll need to call that method.
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I understand..but I am still a little sketchy as to how to write that...any more help? I know it is probably hard to help with this problem. I don't quiet understand yet. Thanks again I really appreciate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic