当总和超过100时仍如何执行总和和平均值,如何获取此代码以停止输入?

当总和超过100时仍如何执行总和和平均值,如何获取此代码以停止输入?,第1张

总和超过100时仍如何执行总和和平均值,如何获取此代码以停止输入?

break
while
循环中使用带
if
条件的语句检查
thesum >100
。希望这些提示能帮助您获得所需的行为。由于您还需要计算平均值,因此将中断逻辑放在avg后面:

     while (input != 0) {    // Use JOptionPane method to accept input from user    input = Float.parseFloat( JOptionPane.showInputDialog( null, "Please enter a number.  Enter 0 to quit: "));    // Invoke sum method and pass input and summation to sum method    theSum = (sum(input, theSum));    // Invoke avg method and pass summation and counter to avg    average = (avg(theSum, counter));    // Increment the counter variable    counter++;    if (theSum > 100)      break;}// Invoke display method and pass summation, average, and counter variables to itdisplay(theSum, average, counter);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5132181.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存