Please tell me the solution of this following program.

/ Calculate a sum Write a program that reads from keyboard numbers and calculates their sum. If the user enters -1, the program should display the sum and terminate. -1 should be included in sum. /

asked 14 Mar '15, 04:59

Rajat's gravatar image

Rajat
315
accept rate: 0%


You must write your solution and people help you. Print ready solutions is prohibited the forum rules.

link

answered 14 Mar '15, 06:26

RabenokDmitry's gravatar image

RabenokDmitry
1263
accept rate: 14%

Does`nt pass testing:( public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String num1 = reader.readLine(); String num2 = reader.readLine(); String num3 = reader.readLine(); int a = Integer.parseInt(num1); int b = Integer.parseInt(num2); int c = Integer.parseInt(num3);

    if (a != -1 && b != -1 && c != -1)

    {
        System.out.println(a + b + c);
    }
    for (;true;){
       if (a == -1 || b == -1 || c == -1)

        System.out.println(a + b + c);
       break;
    }

}

}

link

answered 05 Jan, 17:02

voland's gravatar image

voland
1
accept rate: 0%

Don`t pass testing:( public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String num1 = reader.readLine(); String num2 = reader.readLine(); String num3 = reader.readLine(); int a = Integer.parseInt(num1); int b = Integer.parseInt(num2); int c = Integer.parseInt(num3);

    if (a != -1 && b != -1 && c != -1)

    {
        System.out.println(a + b + c);
    }

    for (;true;)
    {
        if (a == -1 || b == -1 || c == -1)
        {
            break;
        }

    }
    System.out.println(a + b + c);

}

}

link

answered 05 Jan, 17:04

voland's gravatar image

voland
1
accept rate: 0%

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:

×35
×8
×4

Asked: 14 Mar '15, 04:59

Seen: 811 times

Last updated: 05 Jan, 17:04