我刚学会了如何使用静态方法.我试图用这段代码计算每个星球的引力:
/**
* Calculates the acceleration due to gravity on each planet, and then displays the info in a nice table and in a text file
*
* @author Ely Eastman
* @version 14.8.2014
*/
public class GravityV1
{
//method for calulating gravity
public static double [] gravCalc(double [] d, double [] m){
double[] gravFinal = new double [d.length];
for(int i = 0; i < d.length; i++){
gravFinal[i] = ((6.67 * 10E-11) * m[i]) / Math.pow(((d[i] * 1000) / 2) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个程序,以递归方式生成音阶中的音调频率.每个频率是比前一个频率高两个的第十二个根.该程序必须使用递归(呃,教育).当我使用这种方法时,我只是一遍又一遍地重复初始音调.这是为什么?
public static void scale(double x, double z){
double y;
if(z == x){
y = z * Math.pow(2, (1/12));
System.out.println(y);
scale (y, y);
}
else if(z >= (2 * x) - 1 || z <= (2 * x) + 1){
y = z;
System.out.println();
}
else{
y = z * Math.pow(2, (1/12));
scale (y, y);
}
System.out.println(y);
}
Run Code Online (Sandbox Code Playgroud) 我正在编写夏季课程的代码,所以我不必在学校学习入门技术课程.
public class Family {
public static void main(String[] args) throws IOException {
String token = "";
int counter = 0, boyBoy = 0, boyGirl = 0, girlGirl = 0;
double ratioBB = 0.0, ratioBG = 0.0, ratioGG = 0.0;
Scanner inFile = new Scanner(new File("MaleFemale.txt"));
DecimalFormat df = new DecimalFormat("#.##");
while (inFile.hasNextLine()) {
counter++;
token = inFile.nextLine( );
if(token.equals("BB")) boyBoy++;
else if(token.equals("BG") || token.equals("GB")) boyGirl++;
else girlGirl++;
}
ratioBB = (boyBoy / counter) * 100;
ratioBG = (boyGirl / …Run Code Online (Sandbox Code Playgroud)