Clamp to 100 of Maximum
Programming Basics · Java
TASK
Problem
Given two integers `a` and `b`, compute the larger input, then print the value clamped to [-100, 100].
EXAMPLE
Example
7 3
7
LIMITS
Constraints
-1000 ≤ a, b ≤ 1000
LEARN
Theory for this problem
+
The core idea of **Clamp to 100 of Maximum** is to model the requested operation directly: Given two integers `a` and `b`, compute the larger input, then print the value clamped to [-100, 100]. 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 `Math.max(a, b)` and store it as the intermediate result.', 'Then apply `Math.max(-100, Math.min(100, result))` 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 = Math.max(a, b);
long answer = Math.max(-100, Math.min(100, result));
System.out.println(answer);
}
}