Published Apr 3, 2023Updated Apr 11, 2023
Contribute to Docs

The ArithmeticException occurs when an arithmetic operation yields an error.


The ArithmeticException is thrown in the following example because it divides an integer by zero:

public class DivideByZero {
public static void main(String[] args) {
int x = 9/0;

The output would look like this:

Exception in thread "main" java.lang.ArithmeticException: / by zero
at DivideByZero.main(

All contributors

Looking to contribute?

Learn Java on Codecademy