Click here to Skip to main content
16,004,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted
Updated 24-Sep-16 4:59am
Comments
[no name] 24-Sep-16 10:33am    
If you do not understand your homework assignment then you need to ask your teacher. It's not our job to teach you programming even if we could in a forum posting. And, just so you know, "Tried with While, If and Else, but i don't know what to do! " is not what you have tried, it is not java code at all.
GaneshRfromSpace 28-Sep-16 3:03am    
Keywords that cannot be used in codeproject:
1.Homework
2.Lame quotes, "Tried with While,If and else"
Also Your question is unclear, "You want to find average of 50 numbers", is fine, but "you want to show only odd numbers" doesn't add up.
Do you mean to say you want to get input of 50 numbers and display the average as well as the values of type odd which you gave as input ?
Or is it find the average of 50 numbers and display it only if the average is an odd value ?
Now what you can do is,
Google"Java code to find the average of 50 numbers"
Read it understand it, execute it and see in an online compiler or try it in eclipse or netbeans if you have installed.
Now try adding that "Show ODD NUMBER" concept of yours, in your code.
If it throws error post it as a question. People will be happy to help you.
Java is fun kid. Keep learning

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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900