4个回答
展开全部
/**
* 圆形类
*
* @author Joy.Zhou
* @createTime 2013-9-11 下午05:16:37
*/
public class Cirular {
// 半径
private double r;
public Cirular() {
}
public Cirular(double r) {
this.r = r;
}
/**
* 周长
*
* @return
* @throws Exception
*/
public double getGirth() throws Exception {
if (r < 0) {
throw new Exception("the radius is not less then 0 ");
}
return 2 * Math.PI * r;
}
/**
* 面积
*
* @return
* @throws Exception
*/
public double getArea() throws Exception {
if (r < 0) {
throw new Exception("the radius is not less then 0 ");
}
return Math.PI * r * r;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public static void main(String[] args) throws Exception {
Cirular cirular = new Cirular(-4);
System.out.println("周长:" + cirular.getGirth());
System.out.println("面积:" + cirular.getArea());
}
}
展开全部
public class Circle{
public static double perimeterMethod(double r){
double per=Math.PI*2*r;
return per;
}
public static double areaMethod(double r){
double area=Math.pow(r,2.0)*Math.PI;
return area;
}
public static void main(String[] args){
double r=1.0;//半径
double per=0;//周长
double area=0;//面积
per=perimeterMethod(r);
area=areaMethod(r);
System.out.println("周长为:" + per+" "+"面积为:"+area);
}
}
public static double perimeterMethod(double r){
double per=Math.PI*2*r;
return per;
}
public static double areaMethod(double r){
double area=Math.pow(r,2.0)*Math.PI;
return area;
}
public static void main(String[] args){
double r=1.0;//半径
double per=0;//周长
double area=0;//面积
per=perimeterMethod(r);
area=areaMethod(r);
System.out.println("周长为:" + per+" "+"面积为:"+area);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-11
展开全部
public class Circle {
private final double PI=3.14;
private double r;
public Circle(){
}
public double getR() {
return r;
}
public void setR(double r) {
if(r>0){
this.r = r;
}else{
System.out.println("半径要大于0");
}
}
public double getArea(double r){
return PI*r*r;
}
public double getPerimeter(double r){
return 2*PI*r;
}
}
private final double PI=3.14;
private double r;
public Circle(){
}
public double getR() {
return r;
}
public void setR(double r) {
if(r>0){
this.r = r;
}else{
System.out.println("半径要大于0");
}
}
public double getArea(double r){
return PI*r*r;
}
public double getPerimeter(double r){
return 2*PI*r;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询