Dividing by zero

  • 3
  • Locked
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.
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
carlos oliveira
Level 10 , Seattle, United States
9 January, 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); }
Level 10 , Dresden, Germany
9 September 2021, 07:40
Create a very simple divide by zero operation like:
int b = 10/0;
Otherwise the code will not validate.
Level 14
20 July 2021, 10:12
e.printStackTrace() will log the stack trace in the console, no need to wrap this in System.out.printlin()