我無法修復我的代碼。收到錯誤信息是:在java的 「60 45 100 30 20」 在 sun.misc.FloatingDecimal.readJavaFormatString(未知來源) :錯誤:java.lang.NumberFormatException
異常在線程 「主」 java.lang.NumberFormatException:對於輸入字符串.lang.Double.parseDouble(來源不明) 在Lab3.main(Lab3.java:15)
這裏是我的代碼:
import java.io.*;
import java.math.*;
public class Lab3
{
public static void main(String[] args) throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
double pVelocity, pAngle, tDistance, tSize, tElevation;
double radians, time, height, pDistance;
String input = br.readLine();
String[] values = input.split("\\+");
pVelocity = Double.parseDouble(values[0]);
pAngle = Double.parseDouble(values[1]);
tDistance = Double.parseDouble(values[2]);
tSize = Double.parseDouble(values[3]);
tElevation = Double.parseDouble(values[4]);
while(pVelocity != 0 && pAngle != 0 && tDistance != 0 && tSize != 0 && tElevation != 0)
{
radians = pAngle*(Math.PI/180);
time = tDistance/(pVelocity*Math.cos(radians));
height = (pVelocity*time*Math.sin(radians))-(32.17*time*time)/2;
pDistance = time*(pVelocity*Math.cos(radians));
if(pVelocity*Math.cos(radians) == 0)
System.out.print("The computed distance cannot be calculated with the given data.");
else if(height > tElevation && height <= tSize)
System.out.print("The target was hit by the projectile.");
else if(height < tElevation)
System.out.print("The projectile was too low.");
else if(height > tSize)
System.out.print("The projectile was too high.");
else if(pDistance < tDistance)
System.out.print("The computed distance was too short to reach the target.");
else if(height < 0)
System.out.println("The projectile's velocity is " + pVelocity + "feet per second.");
System.out.println("The angle of elevation is " + radians +"degrees.");
System.out.println("The distance to the target is " + tDistance + "feet.");
System.out.println("The target's size is " + tSize + "feet.");
System.out.println("The target is located " + tElevation + "feet above the ground.");
}
}
}
我相信我已經正確地分析我的雙變量轉換爲字符串變量,並且Eclipse在編譯時不顯示更多錯誤。任何人都可以提出解決這個問題?
謝謝你的幫助!這解決了它! – dabad