asked 76.0k views
3 votes
Write a method named circleArea that accepts the radius of a circle as a parameter (as a real number) and returns the area of a circle with that radius. For example, the call of area(2.0) should return 12.566370614359172. You may assume that the radius passed is a non-negative number.

asked
User Cagreen
by
8.0k points

1 Answer

4 votes

Answer:

public static double circleArea(double radius){

double area = 3.142*Math.pow(radius,2);

return area;

}

Step-by-step explanation:

Find the complete program in java that prompts the user to enter a value for radius, stores it in a variable, calls the method circleArea() and passes the value for the radius, then displays the area.

import java.util.Scanner;

public class CocaColaVendingTest {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Please enter the value for radius");

double r = in.nextDouble();

//Calling the method circleArea()

double calcArea = circleArea(r);

System.out.println("The Area is: "+calcArea);

}

public static double circleArea(double radius){

double area = 3.142*Math.pow(radius,2);

return area;

}

}

answered
User KHansen
by
8.0k points

Related questions

asked Dec 11, 2023 65.1k views
Pradas asked Dec 11, 2023
by Pradas
8.3k points
1 answer
4 votes
65.1k views