這個代碼並且不能進行調試工作,有什麼它應該做的是寫在評論任何想法。感謝所有快速回答的人。任何幫助都會很棒。需要幫助調試,新的節目
/*
Debugging: Speed
When corrected, this program accepts an int value for starting mileage, an int value for ending mileage, a double value for time of travel, and then performs the calcualtion necessary to output the miles per hour. The program should exit (quit) after the last window is closed.
*/
public class Speed
{
public static void main(String[] args)
{
//Declare Class Variables
String highway;
int startMiles=0;
double endMiles=0;
double time= 0;
boolean done = false;
while (done)
{
try
{
String start = JOptionPane.showInputDialog(null,"Enter starting mileage: ");
startMiles = Integer.parseInt(start);
String end =JOptionPane.showInputDialog(null,"Enter ending mileage: ");
endMiles = Integer.parseInt(end);
if (endMiles<=startMiles) throw new Exception();
String amount = JOptionPane.showInputDialog(null,"Enter total time as a decimal value: ");
gallons = Integer.parseInt(amount);
done = true;
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Your ending mileage,",endMiles +", must be greater than your starting mileage, " + startMiles, "Error in Mileage", JOptionPane.ERROR_MESSAGE);
}
}
JOptionPane.showMessageDialog(null,"Average speed is "+ (endMiles - startMiles)/time +"miles per hour.");
}
}
您是否嘗試過使用調試器? – OnlyThenDidIReckonMyCurse
你在用什麼IDE?蝕?的IntelliJ? NetBeans的? – Mike
仔細查看所有變量及其聲明。 – vandale