# BigDecimal introduction

BigDecimal: Read and understand how the below methods work by clicking on each of the links below. Later use them to complete the partial code given below.

Note: Retain the precision as 5. While calculating sum and difference, let it be between x and y. Similarly, consider the product of x and y and while calculating the quotient consider x as the dividend and y as the divisor.

Note: Please don’t change the package name.

``````package q10862;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class BigDecimalUsage {
public static void main(String[] args) {
MathContext mathContext = new MathContext(5);
BigDecimal x = new BigDecimal("3.145", mathContext);
BigDecimal y = new BigDecimal("1.792", mathContext);
BigDecimal sum = x.add(y, mathContext); //fill
BigDecimal difference = x.subtract(y); //fill
BigDecimal product = x.multiply(y).setScale(4, RoundingMode.HALF_UP); //fill
BigDecimal quotient = x.divide(y, mathContext);
System.out.println("sum = " + sum);
System.out.println("difference = " + difference);
System.out.println("product = " +product);
System.out.println("quotient = " + quotient);
}
}``````

Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)