public class Chp5 { public static void main(String[] args) { int totalGallons = 0; int gallons; int totalMiles = 0; int miles; double avg1; double avg2; String input,output; input=JOptionPane.showInputDialog("輸入用油加侖數(shù)"); gallons=Integer.parseInt(input); while(gallons!=-1){ output=JOptionPane.showInputDialog("輸入里程數(shù):"); miles=Integer.parseInt(output); totalGallons+=gallons; totalMiles+=miles; avg1=miles/gallons; JOptionPane.showMessageDialog(null, "每加侖所獲得的里程數(shù)為"+avg1, "Result",JOptionPane.INFORMATION_MESSAGE); input=JOptionPane.showInputDialog("輸入用油加侖數(shù)"); gallons=Integer.parseInt(input); } ? ?avg2=totalMiles/totalGallons; JOptionPane.showMessageDialog(null, "總平均里程數(shù)為"+avg2, "Result",JOptionPane.INFORMATION_MESSAGE);}}
幫忙看下哪錯(cuò)了?程序應(yīng)該計(jì)算并顯示各桶油每加侖所獲里程數(shù),然后打印到目前為止總平均里程數(shù)。
慕粉02102016
2016-10-23 15:19:21