3-19 LeadingZeros

posted Feb 1, 2014, 6:48 AM by Dlovan ismail   [ updated Feb 1, 2014, 6:48 AM by Karwan Jacksi ]
//This program displays numbers padded with leading zeros.

package leadingzeros;

public class LeadingZeros 
{
    public static void main(String[] args)
    {
            // Declare a variety of double variables.
            double number1 = 1.234;
            double number2 = 12.345;
            double number3 = 123.456;

            // Display each variable with leading
            // zeros, in a field of 9 spaces, rounded
            // to 2 decimal places.
            System.out.printf("%09.2f\n", number1);
            System.out.printf("%09.2f\n", number2);
            System.out.printf("%09.2f\n", number3);
    }   
}

ċ
LeadingZeros.java
(1k)
Karwan Jacksi,
Feb 1, 2014, 6:48 AM
Comments