Adding

  • 4
What could be simpler and more pleasant than adding numbers? Especially for a robot. Let's write a program where the user enters numbers from the keyboard, and then a special method sums up the entered numbers. And does so until the user gets bored. When the user is bored, he or she enters -1: the program will understand that it's time to wrap things up, and will then display the sum on the screen.
You can't complete this task, because you're not signed in.
Comments(14)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
RoseLevel 8 , Richardson
21 June, 01:42
hint: (sum = sum + number) should be before the if statement
Nickolas JohnsonLevel 8 , St. Louis
5 March, 20:06
This one had me pulling my hair out for a bit until I realized you have to evaluate the keyboard input each time, not the running number that you keep adding to the previous number. After that it was fairly simple.
yehuda bLevel 17 , Beersheba
2 December 2019, 22:53
"-1 should be included in the sum" Didn't include it and got the solution wrong b/c of it.
KIN SOCHEATLevel 29 , Phnom Penh
21 October 2019, 07:20
first write your code and we correct for you... BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); int I = Integer.ParseIn(rd.readLine); ….
Justin SmithLevel 8
2 October 2019, 06:59
This challenge could use a better explanation for the conditions/requirements.
RomanLevel 41
3 October 2019, 06:22
Any suggestions?
Justin SmithLevel 8
4 October 2019, 06:59
Sure. I see that on both lessons 8 and 11 of level 4 you have a minor image of some code using the while(true) loop, but it could use some better explanation on those pages. Perhaps an explanation of what happens to a scanner or reader when it is inside a loop. As for the challenge itself, the opening line (and first requirement) of reading numbers from the keyboard could be confusing for someone new to programming. It could be useful to expand on the "numbers" the program is looking for. I could type in 23464375 and consider that "numbers", but in reality, the program is looking for (or should be looking for) repeated entries of numbers. Just some ideas for clarifications for someone new to programming. Someone who is new may not understand what the challenge is looking for. Cheers, and thanks for a great learning tool!
Alen VlahovljakLevel 7 , Sarajevo
14 June 2019, 16:12
Here is the right answer:
/* DELETED */
RomanLevel 41
18 June 2019, 06:26
Posting the solution in the comments is prohibited.
KIN SOCHEATLevel 29 , Phnom Penh
15 May 2019, 03:52
why not work break; someone can help please
int b= 0;

        while (true) {
            int nN1 = Integer.parseInt(sN1);

            if (nN1 != -1){
                b = b+nN1;
              //  break;
            }else {
                b = b+nN1;
                break;
            }
        }
        System.out.println(b);
      }
}
Clarendon leeLevel 8 , Baltimore
19 October 2019, 20:55
I make the same thing wrong . Need help yet! But,what ? Your question date is 14/May? Nobody answer ? Why. ?
RomanLevel 41
21 October 2019, 05:57
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
PremachandranLevel 35 , Ernakulam
15 October 2018, 13:32
Pl help. Where the code has gone wrong?
RomanLevel 41
16 October 2018, 06:05
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.