java 定义一个圆类Circle,就解
发布网友
发布时间:2023-11-14 12:18
我来回答
共5个回答
热心网友
时间:2024-01-01 07:05
public class Circle {
//圆的半径
private double radius;
//求圆的面积
public double findArea() {
return Math.PI*radius*radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
}
测试类自己去写。
热心网友
时间:2024-01-01 07:05
//亲手打的望采纳
public class Test {
public static void main(String[] args) {
Circle circle = new Circle();
System.out.println("圆的面积为:"+circle.findArea(5));
}
}
class Circle{
private double radius;
public double findArea(double radius){
return radius*radius*Math.PI;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
}
热心网友
时间:2024-01-01 07:06
import java.util.Scanner;public class Circle {
private float radius;//半径
private double findArea(float r)
{
double s =0;
s = Math.pow(r, 2)*Math.PI;
return s;
}//测试
public static void main(String[] args) {
System.out.println(new Circle().findArea(5));
}
}
热心网友
时间:2024-01-01 07:06
class Circle{
double radius;
public double findArea(){
return Math.PI * radius * radius;
}
}
public class TestArea{
public static void main(String[] args){
Circle circle = new Circle();
double area = 0.0;
circle.radius = 2;
area = circle.finaArea();
System.out.println("面积为:" + area);
}
}
热心网友
时间:2024-01-01 07:07
public class Test {
public static void main(String[] args) {
Circle circle = new Circle();
circle.radius = 5;
System.out.println("圆的面积为:" + circle.findArea());
}
}
class Circle {
double radius;// 半径
public double findArea() {
return radius*radius*3.14;
}
}