/ Read numbers from keyboard and calculate their total Read numbers from keyboard and calculate their total until the user enters the word «total». Display to the screen the total. /

I tried the above task as below code:-

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader br       =    null;
        String         in       =    null;
        int            total    =    0;

        br  =   new BufferedReader(new InputStreamReader(System.in));
        in  =   br.readLine();

        while(!in.equalsIgnoreCase("total")){
            try{
                total   =   total   +  Integer.parseInt(in);
            }catch(NumberFormatException nfe){
                total   =   total;
            }
            in      =   br.readLine();
        }

        System.out.println("The Total is::"+total);
    }
}

And on submitting this code to server for testing from my IntelliJID I got the rejection message. though the code is working fine at my end. Please revert back to it.

P.S:- I am eagerly waiting for level 6 materials Please be back..

Best Regards, Shikhar

asked 07 Mar '15, 04:56

sagarwal's gravatar image

sagarwal
112
accept rate: 0%

edited 13 Mar '15, 06:52

Elleonora%20Carry's gravatar image

Elleonora Carry ♦♦
275


Try to write in console only total.

System.out.println(total);
link

answered 07 Mar '15, 09:09

RabenokDmitry's gravatar image

RabenokDmitry
1263
accept rate: 14%

I tried, But still not accepted on server. :( BTW Thanks for writing Dmirty.

(07 Mar '15, 10:48) sagarwal

why didn't you try to find info on this site??

Please read http://help.javarush.net/questions/73/level05lesson12home05

link

answered 07 Mar '15, 12:44

Elleonora%20Carry's gravatar image

Elleonora Carry ♦♦
275
accept rate: 16%

//Passed "total" = "сумма"

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s;
        int t = 0;
        while (!"сумма".equals(s = reader.readLine()))
        {
            t += Integer.parseInt(s);
        }
        System.out.println(t);
    }
}

link

answered 11 Jul, 05:54

blacklight's gravatar image

blacklight
11
accept rate: 0%

edited 11 Jul, 05:55

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10

Asked: 07 Mar '15, 04:56

Seen: 1,487 times

Last updated: 11 Jul, 05:55