-4
我無法真正弄清楚我的錯誤在下面的代碼中。另外:我的代碼看起來很不起眼,如何更好地構建它的任何建議?在Java中使用Math.pow和Math.sqrt時出錯
import java.util.*;
import java.io.*;
import java.lang.Math;
public class FlightSimulator {
public static void main(String[] args){
int time;
int v_y;
int v;
int v_squart;
int height;
Scanner myscan = new Scanner(System.in);
System.out.print("Please enter the time for which you want to output the height of the " +
"plane ");
time = myscan.nextInt();
if(time==0){
System.out.print("The height of the plane is 456 meters over ground.");
}
else{
v_y = 51 - time*3;
v = Math.pow(v_y+20, 2);
v_squart = Math.sqrt(v);
height = 456 - v;
System.out.print("The height of the plane is" + height);
}
}
}
**什麼**錯誤? –
那麼......錯誤信息是什麼?至少你試圖將雙打分配給整數。 – kiheru
你爲什麼要計算一個數的平方的平方根? –