PROBLEM 23
Easy

Sign of Sum

Programming Basics · Java

</>
STATUS Not solved

TASK

Problem

#23

Given two integers `a` and `b`, compute the sum of the two inputs, then print the sign of the result (-1, 0, or 1).

EXAMPLE

Example

Input
7 3
Output
1

LIMITS

Constraints

-1000 ≤ a, b ≤ 1000
📖
LEARN Theory for this problem
+

The core idea of **Sign of Sum** is to model the requested operation directly: Given two integers `a` and `b`, compute the sum of the two inputs, then print the sign of the result (-1, 0, or 1). The reference solution uses `Scanner` for input. Keep only the state needed for this result, choose numeric types that cover the stated bounds, and preserve the exact input/output contract. This makes the solution easier to verify on boundary cases and avoids unrelated work.

💡
NEED HELP? Hints
+

['First compute `a + b` and store it as the intermediate result.', 'Then apply `Long.compare(result, 0)` to that result and print only the final value.']

ANSWER Solution
+
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();

        long result = a + b;
        long answer = Long.compare(result, 0);
        System.out.println(answer);
    }
}