Tuesday, 20 October 2015

Java Tutorial : Java Array (double values)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=jOp7dRnfTZY&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Array (double values)
ArrayDemo.java
class ArrayDemo
{
    public static void main(String[] args)
    {
        // declares an array of doubles
        double[] doubleArray;

        // allocates memory for 10 doubles
        doubleArray = new double[10];

        // initialize first element
        doubleArray[0] = 10.2;
        // initialize second element
        doubleArray[1] = 20.3;
        // and so forth
        doubleArray[2] = 30.8;
        doubleArray[3] = 50.8;
        doubleArray[4] = 90.9;
        doubleArray[5] = 100.8;
        doubleArray[6] = 23.5;
        doubleArray[7] = 99.9;
        doubleArray[8] = 88.4;
        doubleArray[9] = 97.8;

        System.out.println("Element at index 0: " + doubleArray[0]);
        System.out.println("Element at index 1: " + doubleArray[1]);
        System.out.println("Element at index 2: " + doubleArray[2]);
        System.out.println("Element at index 3: " + doubleArray[3]);
        System.out.println("Element at index 4: " + doubleArray[4]);
        System.out.println("Element at index 5: " + doubleArray[5]);
        System.out.println("Element at index 6: " + doubleArray[6]);
        System.out.println("Element at index 7: " + doubleArray[7]);
        System.out.println("Element at index 8: " + doubleArray[8]);
        System.out.println("Element at index 9: " + doubleArray[9]);

    }
}
Output
Element at index 0: 10.2
Element at index 1: 20.3
Element at index 2: 30.8
Element at index 3: 50.8
Element at index 4: 90.9
Element at index 5: 100.8
Element at index 6: 23.5
Element at index 7: 99.9
Element at index 8: 88.4
Element at index 9: 97.8
ArrayLoopDemo.java
class ArrayLoopDemo
{
    public static void main(String[] args)
    {
        // declares an array of doubles
        double[] doubleArray;

        // allocates memory for 10 doubles
        doubleArray = new double[10];

        // initialize first element
        doubleArray[0] = 10.2;
        // initialize second element
        doubleArray[1] = 20.3;
        // and so forth
        doubleArray[2] = 30.8;
        doubleArray[3] = 50.8;
        doubleArray[4] = 90.9;
        doubleArray[5] = 100.8;
        doubleArray[6] = 23.5;
        doubleArray[7] = 99.9;
        doubleArray[8] = 88.4;
        doubleArray[9] = 97.8;

        System.out
                .println("-------------------------------------------------------");
        System.out
                .println("Using for each loop get all elements from doubleArray");
        System.out
                .println("-------------------------------------------------------");

        int i = 0;
        for (double element : doubleArray)
        {
            System.out.println("Element at Index " + i + " : " + element);
            ++i;
        }
    }
}
Output
-------------------------------------------------------
Using for each loop get all elements from doubleArray
-------------------------------------------------------
Element at Index 0 : 10.2
Element at Index 1 : 20.3
Element at Index 2 : 30.8
Element at Index 3 : 50.8
Element at Index 4 : 90.9
Element at Index 5 : 100.8
Element at Index 6 : 23.5
Element at Index 7 : 99.9
Element at Index 8 : 88.4
Element at Index 9 : 97.8
To Download ArrayDemoDoubleApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoDoubleApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment