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("输入用油加仑数");
gallons=Integer.parseInt(input);
while(gallons!=-1){
output=JOptionPane.showInputDialog("输入里程数:");
miles=Integer.parseInt(output);
totalGallons+=gallons;
totalMiles+=miles;
avg1=miles/gallons;
JOptionPane.showMessageDialog(null, "每加仑所获得的里程数为"+avg1,
"Result",JOptionPane.INFORMATION_MESSAGE);
input=JOptionPane.showInputDialog("输入用油加仑数");
gallons=Integer.parseInt(input);
}
avg2=totalMiles/totalGallons;
JOptionPane.showMessageDialog(null, "总平均里程数为"+avg2,
"Result",JOptionPane.INFORMATION_MESSAGE);
}
}
大咪
相关分类