And Java: use biginteger/decimal to store your values and ensure you are setting scale to your required precision, this class offers different rounding methods and are very efficient. Use the static factory method. It can be done in two ways, One way is using setScale, second-way using the round method. round() method. The method accepts either double or float values and returns an integer value. It returns the closest integer to number. This is computed by adding to the number and then flooring it. What is system out printf in Java? The only way to do what you want is to use BigDecimal. in java write a code that suppose the following input is supplied to the program: 9 Then, the output should be: 12096 (99+999+9999+999) Int a ,b,z; a=1;b=4;while (a