Java: 计算扁球体的SA
Java: Calculate SA of oblate spheroid
Write a program Spheroid.java that takes respectively parameters a and c
as command-line arguments and calculates surface area of an oblate spheroid.
他给了我们要使用的公式,但是当我 运行 使用他的示例命令行参数时,我得到了完全不同的东西。他的示例给出 6 和 5 并得到 403.050。我做了我认为正确的事情并得到了 546.1380388013903。我还没有尝试四舍五入,我只是想看看我是否接近。
public class Spheroid {
public static void main(String[] args){
String a = args[0];
String c = args[1];
Double A = Double.parseDouble(a);
Double C = Double.parseDouble(c);
Double e;
Double S;
e = Math.sqrt(1-(Math.pow(C, 2)/Math.pow(A, 2)));
S = (2 * Math.PI * Math.pow(A, 2)) + (Math.PI * ((Math.pow(C, 2)/ Math.pow(e, 2))) * (Math.log((1+e)/(1-e))));
System.out.println(S);
}
}
最后一行应该是
S = (2 * Math.PI * Math.pow(A, 2)) + (Math.PI * ((Math.pow(C, 2)/ e)) * (Math.log((1+e)/(1-e))));
你有 c^2/e^2
而不是 c^2/e
在您的代码中,您使用 Math.pow(e, 2)) 来计算 SA。
然而,在实际公式中它只是 'e' 而不是 e 的 2
次方
Java 中的公式表示不正确。在下面找到您的代码的一些更改:
public static void main(String[] args){
String a = args[0]; //"6";
String c = args[1];; //"5";
double A = Double.parseDouble(a);
double C = Double.parseDouble(c);
double e = Math.sqrt(1-(Math.pow(C, 2)/Math.pow(A, 2)));
double S = (2 * Math.PI * Math.pow(A, 2)) + (Math.PI * ((Math.pow(C, 2)/ e)) * (Math.log((1+e)/(1-e))));
System.out.println(S);
}
输出为:
403.0500218861285
要将其四舍五入为 3dp,您可以使用小数格式:
DecimalFormat newFormat = new DecimalFormat("#.###");
double threeDecimalPlaces = Double.valueOf(newFormat.format(S));
System.out.println(threeDecimalPlaces);
Write a program Spheroid.java that takes respectively parameters a and c as command-line arguments and calculates surface area of an oblate spheroid.
他给了我们要使用的公式,但是当我 运行 使用他的示例命令行参数时,我得到了完全不同的东西。他的示例给出 6 和 5 并得到 403.050。我做了我认为正确的事情并得到了 546.1380388013903。我还没有尝试四舍五入,我只是想看看我是否接近。
public class Spheroid {
public static void main(String[] args){
String a = args[0];
String c = args[1];
Double A = Double.parseDouble(a);
Double C = Double.parseDouble(c);
Double e;
Double S;
e = Math.sqrt(1-(Math.pow(C, 2)/Math.pow(A, 2)));
S = (2 * Math.PI * Math.pow(A, 2)) + (Math.PI * ((Math.pow(C, 2)/ Math.pow(e, 2))) * (Math.log((1+e)/(1-e))));
System.out.println(S);
}
}
最后一行应该是
S = (2 * Math.PI * Math.pow(A, 2)) + (Math.PI * ((Math.pow(C, 2)/ e)) * (Math.log((1+e)/(1-e))));
你有 c^2/e^2
而不是 c^2/e
在您的代码中,您使用 Math.pow(e, 2)) 来计算 SA。 然而,在实际公式中它只是 'e' 而不是 e 的 2
次方Java 中的公式表示不正确。在下面找到您的代码的一些更改:
public static void main(String[] args){
String a = args[0]; //"6";
String c = args[1];; //"5";
double A = Double.parseDouble(a);
double C = Double.parseDouble(c);
double e = Math.sqrt(1-(Math.pow(C, 2)/Math.pow(A, 2)));
double S = (2 * Math.PI * Math.pow(A, 2)) + (Math.PI * ((Math.pow(C, 2)/ e)) * (Math.log((1+e)/(1-e))));
System.out.println(S);
}
输出为:
403.0500218861285
要将其四舍五入为 3dp,您可以使用小数格式:
DecimalFormat newFormat = new DecimalFormat("#.###");
double threeDecimalPlaces = Double.valueOf(newFormat.format(S));
System.out.println(threeDecimalPlaces);