Напишите программу для вычисления суммы двух чисел и распечатайте
выходные данные.
Ввод
Строка 1: целое число.
Строка 2: целое число.
Вывод: вывод состоит из одного целого числа, которое соответствует
сумме, за которым следует новая строка
Пример ввода I
Код: Выделить всё
3
1
Код: Выделить всё
4
Код: Выделить всё
13
10
Код: Выделить всё
23
Код: Выделить всё
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Add {
public static void main(String[] args)throws IOException
{
int a=0, b=0, sum;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the numbers to be summed");
try{
a=sc.nextInt();
sc.nextLine();
b=sc.nextInt();
}
catch(InputMismatchException e){
System.out.println("Please enter an Integer number");
e.printStackTrace();}
catch(Exception e){System.out.println(e);}
sum=a+b;
System.out.println(sum);
sc.close();
}
}
Код: Выделить всё
Wrong Answer Almost there,think some more
Подробнее здесь: https://stackoverflow.com/questions/181 ... 2-integers