21 Answers
New Answerimport java.util.Scanner; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); System.out.println(num1/num2); } catch(ArithmeticException ex) { System.out.println("Еrror: division by zero"); } catch(InputMismatchException ex){ System.out.println("Error: wrong value type"); } } }
7/3/2022 6:36:09 PM
💞Ishani💞21 Answers
New Answer// Copy this code 57.2 Practice No Zeroes import java.util.Scanner; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); /* 1. Еrror: division by zero 2. Error: wrong value type */ //your code goes here System.out.println(num1/num2); } catch(ArithmeticException ae) { System.out.println("Error: division by zero"); } catch(InputMismatchException ime){ System.out.println("Error: wrong value type"); } } }
Just try to rewrite output statement your own, instead of copy from description. There may be mismatching in characters farmat.
YIPMONG Error: division by zero Here Error has a different language letter not English letter which nobody can see. So just copy that from the description and paste in code. Code will work.
Victor Ay I'm trying to create an exception so try catch is needed Is from java code coach
Davinder Kumar but in the code coach it shows me an error Please check my post for visuals of the error
Most likely the problem is in the first error message the E is a different character than the second.
catch(ArithmeticException e) { System.out.print("Error: division by zero"); } //This working fine for me... Try it once.. edit: may be actually use as it is in code comments by copy paste, if it not work..
Davinder Kumar The input is a 0 division That is first input is 1 or any number apart from 0 and the second input is 0
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message