Validate positive input
Java
Easy
6 views
Problem Description
Task: if x is negative, throw IllegalArgumentException. Else return x.
Output Format
Return value
Constraints
Simple validation.
Official Solution
static int requireNonNegative(int x){if(x<0) throw new IllegalArgumentException();return x;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!