且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在java中创建一个显示平均50个数字的程序?

更新时间:2023-02-10 17:30:31

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!



首先考虑如何获取数字 - 我们不知道它们来自何处,但我很确定我不想每次手工输入50个数字 - 而仅显示奇数位意味着什么,我们也不知道,但你的家庭作业问题可能更多明确的。

当你有数字时,其余的都是微不足道的:平均=数字之和/数字数。

所以如果你有3个数字:10,20 ,60然后总和是10 + 20 + 60 = 90,计数是3,所以平均值是90/3 = 30.

所有你需要做的就是显示结果用户。


我们不做你的HomeWork。

HomeWork不会测试你乞求别人做你的工作的技巧,它会帮助你您的老师会检查您对所学课程的理解以及您应用这些课程时遇到的问题。

任何失败都会帮助你的老师发现你的弱点并设定补救措施。

所以,重读你的课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个确切的问题,我们可能会提供帮助。



建议:记一张纸并试着去做手动,你的程序应该使用相同的程序。


Hey guys!

I have a programming class in my school and my teacher put this problem for us to solve, which is to make a program in Java to show the average of 50 numbers but it can only show odd numbers.

Please help!

P.S: I'm a beginner in programming

What I have tried:

Tried with While, If and Else, but i don't know what to do!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

Start by thinking about how to get the numbers - we don't know where they are to come from, but I'm pretty sure I wouldn't want to type in 50 numbers by hand each time - and what the "show only odd numbers" bit means, which we don't know either but your homework question is probably a lot more explicit about.
When you have the numbers, the rest is trivial: average = sum of numbers / count of numbers.
So if you have 3 numbers: 10, 20, 60 then the sum is 10 + 20 + 60 = 90, and the count is three, so the average is 90 / 3 = 30.
All you have to do then is show that result to the user.


We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

Advice: tale a sheet of paper and try to do it by hand, your program should use the same procedure.