wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error" Watch "Error" New topic


Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
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

Joined: Jul 08, 2003
Posts: 24183

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.

[Jess in Action][AskingGoodQuestions]
Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
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
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Sep 08, 2004
Posts: 97
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.
It is sorta covered in the JavaRanch Style Guide.
subject: Error
Similar Threads
Program Output not working
Error - not a statement
Random Access Problem
How close am I in getting this program right?