BigDecimal Constants
Program
import java.math.BigDecimal;
public class BigDecimalConstantsDemo {
public static void main(String[] args) {
BigDecimal zero = BigDecimal.ZERO;
BigDecimal one = BigDecimal.ONE;
BigDecimal ten = BigDecimal.TEN;
System.out.println("Zero constant: " + zero);
System.out.println("One constant: " + one);
System.out.println("Ten constant: " + ten);
// Example arithmetic: TEN * (ONE + ZERO)
BigDecimal result = ten.multiply(one.add(zero));
System.out.println("Result of TEN * (ONE + ZERO): " + result);
// Another example: TEN - ONE
BigDecimal diff = ten.subtract(one);
System.out.println("Result of TEN - ONE: " + diff);
// Using ZERO in comparison
if (zero.compareTo(BigDecimal.ZERO) == 0) {
System.out.println("ZERO constant is equal to zero");
}
}
}
/*
Zero constant: 0
One constant: 1
Ten constant: 10
Result of TEN * (ONE + ZERO): 10
Result of TEN - ONE: 9
ZERO constant is equal to zero
*/