aspose file tools*
The moose likes Beginning Java and the fly likes Methods:  parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Methods:  parameters" Watch "Methods:  parameters" New topic
Author

Methods: parameters

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I have a method:

//Method for testing which calculations to use and return the result
public String calc(String choice, double c, double f)

Now my understanding is the parameter is String.
That is, this method will return something of type String?

So why when I state:


I get the following error on compiling:

C:\java>javac CalcC2F.java
CalcC2F.java:61: incompatible types
found : void
required: java.lang.String
return System.out.println ("When the temperature in celcius is: "
+c +" The temperature in fahrenheit is: "+f);
^
CalcC2F.java:66: incompatible types
found : void
required: java.lang.String
return System.out.println("Sorry, Invalid Data! ");
^
2 errors
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Your return is type String, therefore you should construct the String and return it. e.g.

What you are returning is the "standard" output stream ,hence incompatible types.
Dave Cryder
Greenhorn

Joined: Aug 11, 2004
Posts: 9
The function System.out.println() does not return a value (has a type of "void"). Try this:
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Another quick point, why are you not converting 0.0 celcius into farenheit or vice versa?
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Thanks people - your response is much appreciated!

Re: Nigel Brown's response

Another quick point, why are you not converting 0.0 celcius into farenheit or vice versa?


Good point. As 0.0 C is 32 F. Mmmm - I'm not sure. I will think about this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods: parameters