easyLearn the Basics

User Input / Output

Read two integers and print their sum. This exercise introduces reading standard input and writing a result.

Work through the cases

3 examples

Input notation

Two space-separated integers.

Expected result

Their sum.
Case 1

Input

4 9

Expected output

13
Case 2

Input

-7 2

Expected output

-5
Case 3

Input

0 0

Expected output

0

These notes use simplified input/output notation. The linked platform defines the method signature and judge format.

FROM IDEA TO IMPLEMENTATION

Understand the approach.

Compare the documented approaches below. Brute force, better, and optimal versions appear where available; a direct exercise may need only one approach.

Read both integers and add them. Time and extra space: O(1), excluding input storage.

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<Long> values = new ArrayList<>();
        while (in.hasNextLong()) values.add(in.nextLong());
        long[] a = values.stream().mapToLong(Long::longValue).toArray();
        long n = a[0];
        System.out.println(a[0] + a[1]);
    }
}

Reference code. Platform solutions may use supplied node types, imports, or collection libraries; foundational examples are complete programs.