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);
}
}
/**
* 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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询