Maybe you've been wanting this for a long time, but you were afraid? Drum roll, please! Today we will divide by zero! You actually can do it, if you're careful. Create a public static void divideByZero method that divides any number by zero, and display the result of division. Wrap the method call in a try-catch block and display the exception's stack trace.
Dividing by zero
- 3
Locked
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
carlos oliveira
9 January 2022, 04:37
some task correct answer send me back to the cave:
my primary code didn't pass:
public static void main(String[] args) {
int x=0;
try {
divideByZero(x);
}catch (Exception e) {
e.printStackTrace();
}
}
private static void divideByZero(int x) {
System.out.println(x/0);
}
0
Michael
9 September 2021, 07:40
Create a very simple divide by zero operation like:
Otherwise the code will not validate. 0
Aron
20 July 2021, 10:12
e.printStackTrace() will log the stack trace in the console, no need to wrap this in System.out.printlin()
+4