Java mod examples

Both remainder and modulo are two similar operations; they act the same when the numbers are positive but much differently when the numbers are negative. In Java, we can use Math.floorMod() to describe a modulo (or modulus) operation and % operator for the remainder operation. See the result: | rem & +divisor| rem & -divisor …

Read more

Oracle PL/SQL – ACOS function example

The ACOS() function returns the arc cosine of input n, the input n must be in the range of -1 to 1. The function will return a value in the range of 0 to pi, expressed in radians. ACOS function examples SELECT ACOS(.2) FROM DUAL; — output 1.36943840600456582777619613942212803186 SELECT ACOS(-.4) FROM DUAL; — output 1.98231317286238463861605958925708704694 …

Read more

Oracle PL/SQL – ASIN function example

The ASIN() function returns arc sine of input n, the input n must be in the range of -1 to 1. The function will return a value in the range of -pi/2 to pi/2, expressed in radians. ASIN function examples SELECT ASIN(.25) FROM DUAL; — output 0.25268025514207865348565743699370756609 SELECT ASIN(-.5) FROM DUAL; — output -0.52359877559829887307710723054658381405 SELECT …

Read more

Java 8 – Math Exact examples

Java 8 introduced new methods in the Math class that will throw an ArithmeticException to handle overflows. These methods consist of addExact, substractExact, multiplyExact, incrementExact, decrementExact and negateExact with int and long arguments. In addition, there’s a static toIntExact method to convert a long value to an int that also throws ArithmeticException. Before Java 8 …

Read more

Java – Math.pow example

A simple Math.pow example, display 2 to the power of 8. In Math 2^8 = 2x2x2x2x2x2x2x2 =256 In Java Math.pow(2, 8) Note In Java, the symbol ^ is a XOR operator, DON’T use this for the power calculation. TestPower.java package com.mkyong.test; import java.text.DecimalFormat; public class TestPower { static DecimalFormat df = new DecimalFormat(".00"); public static …

Read more