3-17 Columns

posted Feb 1, 2014, 6:40 AM by Dlovan ismail   [ updated Feb 1, 2014, 6:40 AM by Karwan Jacksi ]
/*
This program displays a variety of
floating-point numbers in a column
with their decimal points aligned.
*/

package columns;

public class Columns 
{
    public static void main(String[] args)
    {
            // Declare a variety of double variables.
            double num1 = 127.899;
            double num2 = 3465.148;
            double num3 = 3.776;
            double num4 = 264.821;
            double num5 = 88.081;
            double num6 = 1799.999;

            // Display each variable in a field of
            // 8 spaces with 2 decimal places.
            System.out.printf("%8.2f\n",num1);
            System.out.printf("%8.2f\n",num2);
            System.out.printf("%8.2f\n",num3);
            System.out.printf("%8.2f\n",num4);
            System.out.printf("%8.2f\n",num5);
            System.out.printf("%8.2f\n",num6);
    }   
}

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