+ 1
How can I resolve this error?
3 Respuestas
+ 2
You can have multiple catch for single try block ;
try {
divident = sc.nextInt();
divisor = sc.nextInt();
int result = divident/divisor;
System.out.println("Result: " + result);
}
catch(java.util.InputMismatchException e)
{
System.out.println("Input integer.");
}
catch(ArithmeticException e) {
System.out.println("Input non-zero Integer.");
}
+ 3
Scanner sc = new Scanner(System.in);
int divident, divisor, result;
try{
divident = sc.nextInt();
divisor = sc.nextInt();
result = divident/divisor;
System.out.println("Result: " + result);
}
catch(java.util.InputMismatchException e){
System.out.println("Input integer.");
}
catch(ArithmeticException e){
System.out.println("Input non-zero Integer.");
}
+ 2
SoloProg
Jayakrishna🇮🇳
Thanks to both of you.