Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
661 B
1
Indexable
Never
// File: arithmetic/Operations.java
package arithmetic;

public class Operations {
    public static double addition(double num1, double num2) {
        return num1 + num2;
    }

    public static double subtraction(double num1, double num2) {
        return num1 - num2;
    }

    public static double multiplication(double num1, double num2) {
        return num1 * num2;
    }

    public static double division(double num1, double num2) {
        if (num2 != 0) {
            return num1 / num2;
        } else {
            System.out.println("Cannot divide by zero.");
            return Double.NaN; // NaN represents undefined result
        }
    }
}
Leave a Comment