计算输入值? [英] Count input values?
问题描述
我正在尝试编写一个读取未指定数量的正值和负值的程序,对它们进行计数并计算输入值的平均值,而不是计算零。程序应以输入0结束,并将平均值显示为浮点数。
我可以使用什么来计算输入值?
示例:如果我输入1,2和0,则平均值应为1.5
Ps:我是初学者...
I''m trying to write a program that reads unspecified number of positive and negative values, counts them and computes the average of the input values, not counting zeros. The program should end with the input 0 and display the average as a floating point number.
What can I use to count the input values?
Example: If I type 1, 2 and 0 the average should be 1.5
Ps: I''m a beginner...
推荐答案
我正在尝试编写一个读取未指定数量的正值和负值的程序,计算它们并计算输入值的平均值,不计算零。程序应以输入0结束,并将平均值显示为浮点数。
我可以使用什么来计算输入值?
示例:如果我输入1,2和0,则平均值应为1.5
Ps:我是初学者...
I''m trying to write a program that reads unspecified number of positive and negative values, counts them and computes the average of the input values, not counting zeros. The program should end with the input 0 and display the average as a floating point number.
What can I use to count the input values?
Example: If I type 1, 2 and 0 the average should be 1.5
Ps: I''m a beginner...
了解Scanner类(用于读取输入)并尝试该程序。你应该使用while循环。
如果你遇到代码就发布。
Read about the Scanner class (for reading the input) and try the program. You should make use of a while loop.
Post if you get stuck with the code.
阅读关于Scanner类(用于读取输入)并尝试该程序。您应该使用while循环。
如果您遇到代码,请发布。
Read about the Scanner class (for reading the input) and try the program. You should make use of a while loop.
Post if you get stuck with the code.
是的我知道如何读取输入,但我如何计算?
Yes I know how to read the input, but how do I count it ?
是的我知道如何阅读输入,但我如何计算?
Yes I know how to read the input, but how do I count it ?
你如何在现实生活中统计它们?考虑一下,然后你会找到答案。
PS:你有没有发现,如果这个数字是正数还是负数?那是当然的第一步。
问候,
Nepomuk
How would you count them in real life? Think about that, then you''ll find the answer.
PS.: Have you found out yet, if the number is positive or negative? That''s the first step of course.
Greetings,
Nepomuk
这篇关于计算输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!