0
public class Program { static int div(int a, int b) { if(b == 0) { throw ArithmeticException("Division by Zero"); } else { x = a/b; return x; } } public static void main(String[] args) { int x= div(42,2); System.out.println(x); } } what is wrong with this code ..
5 ответов
+ 1
The below code is what you're suppose to write.
throw new ArithmeticException("......");
You might also need to declare the throws keyword after the method signature if asked so.
+ 1
do .... static int div(int a,int b) throws ArithmeticException
0
use new to create anonymous object of the exception u wanna throw also u may always use try catch block if that won't work
0
x is undefined inside div method
0
syntax for throwing an exception is wrong...use 'throw new ArithmeticException("");' instead of throw ArithmeticException("");