如何在循环中计算最小值,最大值(java) [英] How to count min,max in loop (java)
本文介绍了如何在循环中计算最小值,最大值(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法为明天的演讲编写1个应用程序.
I have problem with coding 1 app for toomorow lectures.
所以, 该程序要求用户输入数字,在键入"100"时,它停止了,并显示: -平均 -分钟 -最大
So, That program ask user for numbers, on typed "100" it's stops, and it shows: -average -min -max
我知道我需要使用哪种循环(做对吗?). 但是我如何不使用数组来计算平均值,最小值,最大值呢?
I know what kind of loop, i need to use (do-while right?). But how i'm suppoused to count average,min,max without using arrays ?
推荐答案
这是简写的伪代码,因为您必须自己对此进行编码:
this is shorthand pseudo code because you have to code this yourself:
min = max = total = user_input
count = 0
do {
count++
input = get_input
total += input
min or max maybe = input
} while (input !=100)
average = total / count
print stuff
祝你好运
这篇关于如何在循环中计算最小值,最大值(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文