7-11 计算正五边形的面积和周长 (10 分)
题意
正确代码
import java.text.DecimalFormat;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
double a=sc.nextDouble();
double s=a*a*Math.sqrt(25.0+10.0*Math.sqrt(5.0))/4.0;
double c=a*5;
DecimalFormat df=new DecimalFormat("#.####");
System.out.printf(df.format(s));
System.out.println();
System.out.printf(df.format(c));
sc.close();
}
}
错误代码
错误原因:不会....
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
double a=sc.nextDouble();
double s=a*a*Math.sqrt(25.0+10.0*Math.sqrt(5.0))/4.0;
double c=a*5;
System.out.printf("%.4f\n",s);
System.out.printf("%.4f\n",c);
sc.close();
}
}