java中怎么去定义一个圆类,其有半径属性,并在类中写两个方法来分别计算周长和面积
发布网友
发布时间:2022-04-29 15:56
我来回答
共1个回答
热心网友
时间:2023-10-17 07:31
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);
}
}
热心网友
时间:2023-10-17 07:31
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);
}
}
热心网友
时间:2023-10-17 07:31
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);
}
}
热心网友
时间:2023-10-17 07:31
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);
}
}
热心网友
时间:2023-10-17 07:31
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);
}
}