ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1000. A+B Problem

Help me find out the error. (Wrong Answer)
Послано Ravi Kiran Kanneganti 29 ноя 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)
Послано Oleg Baskakov 29 ноя 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.