java 定义一个圆类Circle 包含私有成员r,voidsetR(double)设置圆的半径,doublearea()计算圆的面积

如题所述

import java.util.*;
public class Circle {
private double r;
Scanner sc=new Scanner(System.in);
public Circle(){
super();
System.out.println("输入圆的半径:");
r=sc.nextDouble();
setR(r);
double s=getArea();
System.out.println("圆的面积S="+s);
}
public void setR(double r){
this.r=r;
}

public Double getArea(){
double s=(Math.PI)*(Math.pow(this.r, 2));
return s;
}

public static void main(String[] args){
new Circle();
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答

java 定义一个圆类Circle 包含私有成员r,voidsetR(double)设置圆的半 ...
public Circle(){ super();System.out.println("输入圆的半径:");r=sc.nextDouble();setR(r);double s=getArea();System.out.println("圆的面积S="+s);} public void setR(double r){ this.r=r;} public Double getArea(){ double s=(Math.PI)*(Math.pow(this.r, 2));return s...

java编程 定义一个类:圆 属性:半径 方法:(1)计算周长、面积 (2)设置半...
class Circle { private double r;public void setR(double r){ this.r=r;} public double getArea(){ return Math.PI*r*r;} public double getPerimeter(){ return 2*Math.PI*r;} public double getRadius(){ return r;} public static void main(String args[]){ Circle c1=new Circle...

JAVA中怎么定义一个圆类 要求如下
public class Circle { private double r;public Circle(double r) { this.r = r;} public double getR() { return r;} public void setR(double r) { this.r = r;} \/ 面积 return \/ public double getArea() { return Math.PI * Math.pow(r, 2);} \/ 周长 return \/ public doub...

JAVA:定义一个圆类Circle,成员变量:半径 radius;
public class Main{ public static void main(String[] ags) { double radius = 2.5; double width = radius * 2; double height = 10; Circle circle = new Circle(radius); System.out.println("圆形周长:" + circle.calculgirth()); System.out.println("圆形面积...

java编程:定义一个圆类,属性为半径,方法为对输入的半径计算其周长和面...
java编程定义一个类圆属性半径,方法计算周长面积设置半径读取半径 class Circle {\\x09private double r;\\x09public void setR(double r)\\x09{ \\x09\\x09this.r=r;\\x09} \\x09public double getArea()\\x09{ \\x09\\x09return Math.PI*r*r;\\x09} \\x09public double getPerimeter()\\x09{ \\x09\\x09...

java定义一个圆类用来表示二维空间中的一个圆,包括了圆心坐标和半径
public class Circle { public Circle(double cx, double cy, double r) { centerX = cx; centerY = cy; radius = r; } public Circle() { this(0, 0, 0); } public void setCenter(double cx, double cy) { centerX = cx; centerY = cy; } public...

定义一个圆类Circle,描述圆对象.圆有一个属性radius表示半径,有三个方...
void main(){ Circle yuan;float rr;cout<<"请输入圆半径:"< yuan.registCircle(rr);cout<<"圆的半径为:"< cout<<"圆的周长为:"< cout<<"圆的面积为:"< },5,定义一个圆类Circle,描述圆对象.圆有一个属性radius表示半径,有三个方法:一个setR(double r)用于修改半径的值 一个getR(...

定义一个圆类(Circle)
void Circle::SetR(double R){ r=R;Area=r*r*3.14159265;Circumference=2*r*3.14159265;} int main(){ Circle cl1(2),cl2,cl3=cl1;cout<<"圆半径:"<<cl3.GetR()<<'\\t'<<"圆周长:"<<cl3.GetCircumference()<<'\\t'<<"圆面积:"<<cl3.GetAreaCircle()<<endl;cl2.SetR(4);...

JAVA编程题,构造一个Circle类实现圆。急!!
Math.PI * 2 * radius;}public Double getRadius() {return radius;}public void setRadius(Double radius) {this.radius = radius;}}import java.util.Scanner;public class App {public static void main(String[] args) {Scanner input = new Scanner(System.in);Circle circle = new Circle...

java类的创建,Circle
public class Circle { private double radius;private double area;private double diameter;public double calDiameter(){ return 2 * radius;} public double calArea(){ return Math.PI * calDiameter();} public double getRadius() { return radius;} public void setRadius(double radius) ...

相似回答