Page 1 of 1

Which is output when inputVal is -5? try { inputVal = scnr.nextInt(); if (inputVal < 0) { throw new Except

Posted: Tue Jul 12, 2022 8:15 am
by answerhappygod
Which is output when inputVal is -5?
try { inputVal = scnr.nextInt(); if (inputVal < 0) { throw new Exception("Input should bepositive"); } System.out.print("Input squared: " + inputVal *inputVal);}catch (Exception e) { System.out.print(e.getMessage());}
Input squared: 25
Exception
Input should be positive
Input squared: 25Input should be positive