+ 5

Please help me solve this question in java and where did I go wrong?🤔

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(); 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"); } } }

3rd Jul 2022, 6:36 PM
Sokkai
Sokkai - avatar
21 Answers
+ 5
// 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"); } } }
3rd Jul 2022, 8:03 PM
SoloProg
SoloProg - avatar
+ 5
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.
3rd Jul 2022, 8:54 PM
A͢J
A͢J - avatar
+ 4
Just try to rewrite output statement your own, instead of copy from description. There may be mismatching in characters farmat.
3rd Jul 2022, 7:41 PM
Jayakrishna 🇮🇳
+ 4
SoloProg Sir yours worked👍 But how🤔 Thank you so much for the help🤗
3rd Jul 2022, 8:41 PM
Sokkai
Sokkai - avatar
+ 3
Try removing try catch error
3rd Jul 2022, 6:50 PM
Victor [The Coder]
Victor [The Coder] - avatar
+ 3
Victor Ay I'm trying to create an exception so try catch is needed Is from java code coach
3rd Jul 2022, 6:53 PM
Sokkai
Sokkai - avatar
+ 3
What the name of the code coach
3rd Jul 2022, 6:54 PM
Victor [The Coder]
Victor [The Coder] - avatar
+ 3
// Try it System.out.println( (double) num1/num2 );
3rd Jul 2022, 6:56 PM
SoloProg
SoloProg - avatar
+ 3
what error you are having ?
3rd Jul 2022, 6:56 PM
Davinder Kumar
Davinder Kumar - avatar
+ 3
Victor Ay Multiple exceptions
3rd Jul 2022, 7:01 PM
Sokkai
Sokkai - avatar
+ 3
it is working fine.
3rd Jul 2022, 7:13 PM
Davinder Kumar
Davinder Kumar - avatar
+ 3
Davinder Kumar but in the code coach it shows me an error Please check my post for visuals of the error
3rd Jul 2022, 7:15 PM
Sokkai
Sokkai - avatar
+ 3
tell me first, what input are you giving ??
3rd Jul 2022, 7:16 PM
Davinder Kumar
Davinder Kumar - avatar
+ 3
Most likely the problem is in the first error message the E is a different character than the second.
3rd Jul 2022, 7:16 PM
SoloProg
SoloProg - avatar
+ 3
Jayakrishna🇮🇳 I did that but still I got same error
3rd Jul 2022, 7:43 PM
Sokkai
Sokkai - avatar
+ 3
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..
3rd Jul 2022, 7:59 PM
Jayakrishna 🇮🇳
+ 3
Ok Jayakrishna🇮🇳 Thank you so much sir Let me check it out
3rd Jul 2022, 8:02 PM
Sokkai
Sokkai - avatar
+ 2
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
3rd Jul 2022, 7:19 PM
Sokkai
Sokkai - avatar
+ 1
Davinder Kumar Let me use playground and send you the link and error in a post
3rd Jul 2022, 7:02 PM
Sokkai
Sokkai - avatar
+ 1
SoloProg it didn't work😓
3rd Jul 2022, 7:02 PM
Sokkai
Sokkai - avatar