Home / Questions / Which arithmetic operations can result in the throwing of an ArithmeticException?
Explanatory Question

Which arithmetic operations can result in the throwing of an ArithmeticException?

👁 2,263 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

In Java, the ArithmeticException is mainly thrown during arithmetic operations that result in illegal or undefined results, particularly division by zero using integer types.


💡 Detailed Explanation:

The only arithmetic operation that can cause an ArithmeticException in Java is:

Integer division or modulus (%) by zero.


🧮 Examples:

✅ Example 1 — Division by zero


int a = 10;
int b = 0;
int c = a / b; // ❌ Throws ArithmeticException: / by zero
 

✅ Example 2 — Modulus by zero

 

int x = 25;
int y = 0;
int z = x % y; // ❌ Throws ArithmeticException: / by zero

⚙️ Note:

  • This exception occurs only with integer types (int, long, short, byte).

  • Floating-point division (float, double) does not throw an exception — it results in:

    • Infinity (for positive/negative division by zero), or

    • NaN (Not a Number).

Example:

 

double a = 10.0;
double b = 0.0;
System.out.println(a / b); // ✅ Outputs: Infinity

🧠 Summary:

In Java, integer division (/) or modulus (%) by zero are the operations that can throw an ArithmeticException.