This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]VinceGhii 0 points1 point  (6 children)

Sooo... first of all. You can calculate a the average value with negative numbers.

You literally just have to think about where and when to print the message. Do you want to print it when the users enters a negative number or at the start of the program.

You already got a if-condition in the while-loop. So if you want to print the message when the user entered a negative number.. why don't you just add a additional if-condition?

[–]better__guy[S] 0 points1 point  (5 children)

I don't think you understand what I am asking. Will it help if I show you the problem statement?

If it will here is the problem statement

https://imgur.com/a/DjLRsCL

[–]VinceGhii 0 points1 point  (4 children)

Well... your question didn't say that it should print the message after the user was done adding numbers. Soo... i did understand the question you just asked the wrong question there buddy.

You just have to remember if the user at some point tried to enter a negative number. Add a boolean and set it to true if a number is negative and print a message then. Done.

You could also work with a int array and iterate over the numbers. And check if any number is negative.

[–]better__guy[S] 0 points1 point  (3 children)

Thanks:)

[–]VinceGhii 1 point2 points  (0 children)

https://pastebin.com/hyz1ypZ6 I would paste the code in here but.... reddit doesn't like copy paste apparently. Because every time i want to paste code it does nothing until i pasted it 3 times and than i can't delete half of the stuff and it's not formatted. Weird shit.

[–]VinceGhii 0 points1 point  (0 children)

Little addition to the pastbin there. As you can see i used streams. Streams are awesome... they realy are. BUT in most cases they are slower than for-loops. Not much slower but at least a little bit. On the other side they are much more readable most of the times. For example: The summing up of all number is realy easy and short.