第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

幫忙看下哪錯(cuò)了?程序應(yīng)該計(jì)算并顯示各桶油每加侖所獲里程數(shù),然后打印到目前為止總平均里程數(shù)。

幫忙看下哪錯(cuò)了?程序應(yīng)該計(jì)算并顯示各桶油每加侖所獲里程數(shù),然后打印到目前為止總平均里程數(shù)。

慕粉02102016 2016-10-23 15:19:21
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);}}
查看完整描述

1 回答

?
大咪

TA貢獻(xiàn)785條經(jīng)驗(yàn) 獲得超332個(gè)贊

package?zzzz;

import?javax.swing.JOptionPane;

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);
if(gallons!=-1){????????????????//這里判斷的時(shí)候有問(wèn)題,用if去判斷別用while,用while成了死循環(huán)了,所以不會(huì)往下執(zhí)行
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("請(qǐng)?jiān)俅屋斎胗糜图觼鰯?shù)");????????//這里我給你加了兩個(gè)字
gallons=Integer.parseInt(input);
}
??avg2=totalMiles/totalGallons;
??JOptionPane.showMessageDialog(null,?"總平均里程數(shù)為"+avg2,
??"Result",JOptionPane.INFORMATION_MESSAGE);
}
}

輸入的時(shí)候也是,里數(shù)要大于用油加侖數(shù),負(fù)責(zé)會(huì)異常,因?yàn)樾?shù)的問(wèn)題除出來(lái)以后都是0.XX,然后在轉(zhuǎn)為整形后就變成0了

查看完整回答
1 反對(duì) 回復(fù) 2016-10-23
  • 1 回答
  • 0 關(guān)注
  • 1514 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)