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
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
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