ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1000. A+B Problem

Help me find out the error. (Wrong Answer)
Posted by Ravi Kiran Kanneganti 29 Nov 2016 12:30
Java Program:

import java.io.PrintWriter;
import java.util.Scanner;

public class Sum
{
    public static void main ( String [] args )
    {
        /**
         * Initialize
         */
        Scanner inputs = null;
        PrintWriter output = null;

        try
        {
            if ( args != null && args.length == 2 )
            {
                /**
                 * Read Inputs
                 */
                inputs = new Scanner ( System.in );

                /**
                 * For Printing Output
                 */
                output = new PrintWriter ( System.out );

                Integer a = inputs.nextInt ();
                Integer b = inputs.nextInt ();

                output.println ( a + b );
            }
            else
            {
                System.out.println ( "Only 2 Integer values are accepted as input" );
            }
        }
        catch ( Exception e )
        {
            System.out.println ( "There is an error while executing this program : " + e );
        }
        finally
        {
            if ( inputs != null )
                inputs.close ();

            if ( output != null )
            {
                output.flush ();
                output.close ();
            }
        }
    }
}
Re: Help me find out the error. (Wrong Answer)
Posted by Oleg Baskakov 29 Nov 2016 13:11
You don't really need to check for amount of arguments, you just need to read what you're asked for. Attempt to do this simplier, without try-catch-finally construction.