Consider the following method for converting milliseconds in

Consider the following method for converting milliseconds into days://converts milliseconds to days public static double toDays(double millis) (return millis/1000.0/60.0/60.0/24.0;) Write a similar method named area that takes as a parameter the radius of a circle and that returns the area of the circle. For example, the call area (2.0) should return 12.566370614359172. Recall that area can be computed as pi times the radius squared and that Java has a constant called Math. PI.

Solution

Code in AreaCircle.java file
import java.util.*;
import java.lang.Math;
//class AreaCircle
public class AreaCircle
{

/*main method*/
public static void main(String args[])
{
/*call the method area */
System.out.println(\"area of the circle is given radius=2.0 :\"+area(2.0));
}
//end of main method

public static double area(double radius)
{
double areaofcircle=Math.PI*radius*radius;   /*Area of a circle=pi*r*r */
return areaofcircle;
}//end of area method
}//end of class

Here actual and formal parameters are used to call a method.
A parameter is a variable that pass the value to called function.

Actual parameter: A variable or expression refrenced in the parameter list of a subprogram call.

Formal parameter:A variable declared in the parameter list of a subprogram specification.Formal parameters are the placeholders for the values of actual parameter.

Math.PI is a java constant to calculate phi value in Java

 Consider the following method for converting milliseconds into days://converts milliseconds to days public static double toDays(double millis) (return millis/1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site