java中怎么去定义一个圆类,其有半径属性,并在类中写两个方法来分别计算周长和面积

如题所述

import java.text.DecimalFormat;
/**
* Created by ASUS on 2018/10/24.
*/
public class test {
static final double p = 3.14;
//圆的面积为
public static double c(double r){
return p*r*r;
}
//圆的周长
public static double s(double r){
return 2*p*r;
}
public static void main(String [] arge){
System.out.println(fmt(c(2.3d)));
System.out.println(fmt(s(2.3d)));
}

private static String fmt(double rest){
DecimalFormat df = null;
df = new DecimalFormat("###,##0.00");
return df.format(rest);
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答

java中怎么去定义一个圆类,其有半径属性,并在类中写两个方法来分别计算...
import java.text.DecimalFormat;\/ Created by ASUS on 2018\/10\/24.\/ public class test { static final double p = 3.14;\/\/圆的面积为 public static double c(double r){ return p*r*r;} \/\/圆的周长 public static double s(double r){ return 2*p*r;} public static void main(Stri...

java编程 定义一个类:圆 属性:半径 方法:(1)计算周长、面积 (2)设置半...
Circle c2=new Circle();c1.setR(50);c2.setR(80);System.out.printf("c1面积为:%.3f\\r\\n",c1.getArea());System.out.printf("c1周长为:%.3f\\r\\n",c1.getPerimeter());System.out.printf("c2面积为:%.3f\\r\\n",c2.getArea());System.out.printf("c2周长为:%.3f\\r\\n",...

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:定义一个圆类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设计一个圆类Circle,并测试,要求: Circle类中有两个成员方法,一个...
public class CircleTest { public static void main(String[] args) { double radius = 10;Circle circle = new Circle();circle.setRadius(radius);System.out.println("半径" + radius + "的圆,周长: " + circle.perimeter() + ", 面积: " + circle.area());double radius2 = 11;Cir...

java编写一个应用程序,创建一个圆类,在类中定义半径成员变量,如何求其...
System.out.println("圆的周长为-->"+this.perimeter(radius)+"\\n"+ "圆的面积为-->"+this.area(radius));} } public class OperateDemo{ public static void main(String args[]){ Round round=new Round();System.out.print("请输入圆的半径-->");Scanner scan=new Scanner(System.in)...

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 ...

用java编写一个圆类Circle,该类拥有:一个成员变量 radius(私有,浮点型...
创建一个圆类Circle,该类可以接收圆半径,并具有计算圆周长和面积的方法。import java.math.*;import javax.swing.*;class Circle{ int r;Circle(int r){ this.r=r;} public void getS(){ System.out.println("面积是:"+Math.PI*r*r);} public void getL(){ System.out.println("周长...

用java语言定义一个Circle类求圆面积,用有、无参构造方法,设计并实现两 ...
} \/\/ 无参构造函数 public Circle(){ this(0); \/\/ 调用有参构造函数,初始化半径为0 } \/\/ 求面积public double area(){ return radius*radius*PI;}\/\/ 定义Circle类的对象,通过对象成员方法输出圆的面积public static void main(String args[]) { Circle circle = new ...

java 定义一个圆类Circle 包含私有成员r,voidsetR(double)设置圆的半 ...
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...

相似回答