If the result of the code for a problem shows expected output to be the same as my output, how can I know what I did wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If the result of the code for a problem shows expected output to be the same as my output, how can I know what I did wrong?

9th Mar 2021, 3:59 PM
dana ciupe
dana ciupe - avatar
6 Answers
+ 2
My solution... 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 e1) { System.out.println ("Error: division by zero"); } catch(InputMismatchException e2) { System.out.println ("Error: wrong value type"); } } }
10th Mar 2021, 7:59 PM
dana ciupe
dana ciupe - avatar
0
Hi! if the expected output and the output of your code are the same, then the output is correct. you have nothing to worry about, if they are different then you made a mistake somewhere. Please, give us a specific example
9th Mar 2021, 4:52 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
It's with the problem from exceptions... when the value introduced are 5 and 0 my output is Error: division by zero and expected output is the same...but they show it didn't pass the test
9th Mar 2021, 5:14 PM
dana ciupe
dana ciupe - avatar
0
ask a specific question, if this is a problem, write the problem condition, and be sure to attach your solution attempt code. this way you will get as much help as possible
9th Mar 2021, 5:30 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Problem...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 "Еrror: division by zero"; and for the second one, "Error: wrong value type". Sample Input 1 b Sample Output Error: wrong value type
10th Mar 2021, 7:59 PM
dana ciupe
dana ciupe - avatar
0
I'm sorry, you did everything right, provided the task and the solution to it, but apparently no one else answered you except me... And I'm not good at java... if this continues, delete this branch and create a new question, where in the description, attach your code, which will be located in your code store { } and insert a link to it in the question. this will increase the chances of help
10th Mar 2021, 8:27 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar