Write a method that has the radius of the circle passed into it. It computes the
ID: 3532324 • Letter: W
Question
Write a method that has the radius of the circle passed into it. It computes the area, and returns the area to the main method.
Also, write a line of code that might "call" the method from the main method. Example: x = theMethod(z);
This is what I have so far:
public class Circle {
public static double circleArea (double radius) {
double area = radius * radius * Math.PI ;
return area ;
}
// Main method
public static void main(String[ ] args) {
double radius = 0
try{
Explanation / Answer
Code for beginner like you, easy to understand,plz comment if have any doubt
import java.util.*;
class Circle
{
public Circle()
{
}
public double circleArea (int radius)
{
double area = radius * radius * Math.PI ;
return area ;
}
}
class Program
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
int r= s.nextInt();
Circle c= new Circle();
double area=c.circleArea(r);
System.out.println("Area "+area);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.