+ 2

On Java practice 58.2 what is 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(); /* 1. Еrror: division by zero 2. Error: wrong value type */ //your code goes here System.out.println(num1/num2); } catch(ArithmeticException ex) { System.out.print("Error: division by zero "); } catch(InputMismatchException ex){ System.out.println("Error: wrong value type"); } } } // on #2 //Your output : Error: division by zero //expected output: Error: division by zero // same output. somehow failed.

8th Apr 2022, 3:29 AM
makoto tanaka
makoto tanaka - avatar
10 Answers
+ 3
You have an extra space at the end.
8th Apr 2022, 4:03 AM
Simon Sauter
Simon Sauter - avatar
+ 2
Hm. Try with "println" instead of "print".
8th Apr 2022, 6:16 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Thank you. But failed again.
8th Apr 2022, 5:36 AM
makoto tanaka
makoto tanaka - avatar
0
It failed. Sorry.
8th Apr 2022, 8:13 AM
makoto tanaka
makoto tanaka - avatar
0
Now l succeeded by copy and paste the message written by the problem maker.
8th Apr 2022, 8:19 AM
makoto tanaka
makoto tanaka - avatar
0
How was this solved?
10th May 2022, 4:53 PM
Bernard Edwards
0
By Copy and Paste the " Error: division by zero" . This problem was Same appearance with different code. Maybe l used an input system which can input Japanese.
11th May 2022, 8:44 AM
makoto tanaka
makoto tanaka - avatar
0
Как это решить? Я не понимаю
27th May 2022, 12:46 PM
Rkkkkkkk
Rkkkkkkk - avatar
0
You need to write a divider program which will operate with integers, The program you are given should take two integers as input and execute the division, but we need to handle two exceptions: 1. the divider shouldn't be zero 2. both inputs should be integers. Complete the program to handle them. For the first exception, the program should output "Mistake: division by zero"; and for the second one, "Mistake: wrong value type". Sample Input 1 b Sample Output Mistake: wrong value type
11th Feb 2023, 11:41 AM
Alalinga Fatawu Iddrisu
Alalinga Fatawu Iddrisu - avatar
0
My answer Working 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(); if (num2 == 0) { throw new ArithmeticException("Error: division by zero"); } System.out.println(num1 / num2); } catch (ArithmeticException e) { System.out.println(e.getMessage()); } catch (InputMismatchException e) { System.out.println("Error: wrong value type"); } finally { scanner.close(); } } }
27th Jun 2024, 12:39 AM
PYSCODES
PYSCODES - avatar