Credits

Saturday, February 28, 2009

Methods with Parameters and Returned Values in Java

A method in Java may contain parameters and may or may not return values. The data type of the returned value shall determine the datatype of the method.

Check the sample program below.



[+/-] show/hide



public class samplemethods2{
public static void main(String [] args){
double radius=5,pi=3.1416;
samplemethods1.init();
System.out.print("The area is "+compute(radius,pi) );
}

public static double compute(double rad,double PI)
{
return rad*PI; */the result of this is passed to the invoking class*/
}}

AddThis