Let's assume x is the divisor and it may possibly by 0.
The program runs this:
Scanner reader = new Scanner(System.in);
int y = 5;
int x = 0;
x = reader.nextInt();
System.out.println("y divided by x is " + y/x);
I know that if a program finds out that it it's dividing a variable by 0 it'll throw an ArithmeticException.
While that's fine, there are alternatives to finding out such as using an if statement to check if x is 0 before doing any dividing or doing a try/catch block.
What's the most efficient way of making sure the program doesn't divide a variable by 0?