Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compilation error

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
hi i wrote a code to convert from inches to cm. i am not creating any object.....just only methods...its C style programming....but getting compilation error.
Code:
class Calculate
{  
	
   double factor = 2.54;

   
   public static void main (String[] args)
   
   {  
	   double inches = 12;
	   calculate(inches);//calling the function
   }

 
   void static calculate (double m)
     {  double result;
      result = factor * m;
      System.out.println(m + " inches = " + result + " cm.");
     }
}

javac Calculate.java
Calculate.java:15: <identifier> expected
void static calculate (double m)
^
Calculate.java:20: '(' expected
}
^
Calculate.java:11: cannot resolve symbol
symbol : method calculate (double)
location: class Calculate
calculate(inches);
^
3 errors
>Exit code: 1

why getting error.

i want to know the cause of error and how to remove it??

thanks...
 
I think you just need to put the identifier before the method like the error states. So put private, public or protected before void for your calculation method.
 
no it did not work. i removed void and usued public....but error continued...is there any other problem??

but it should work...i can call any function from main...what is the problem?

as i am not creating any object so i have usued static keyword in front of calculate (double m). if i remove static from calculate (double m) it is saying error: <calling non static method >

so what could be the problem?? how can i run this code?
 
I think you should put static before void.

Ion Filipski
1c.bmp
 
yes its working now... i changed

static double factor = 2.54;
and
static void calculate (double m)

thanks


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top