Friday, 23 October 2015

Java Tutorial : Java Array (float values)


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

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

        // allocates memory for 10 floats
        floatArray = new float[10];

        // initialize first element
        floatArray[0] = 11.1f;
        // initialize second element
        floatArray[1] = 11.2f;
        // and so forth
        floatArray[2] = 11.3f;
        floatArray[3] = 12.1f;
        floatArray[4] = 12.2f;
        floatArray[5] = 12.3f;
        floatArray[6] = 13.1f;
        floatArray[7] = 13.2f;
        floatArray[8] = 13.3f;
        floatArray[9] = 14.1f;

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

    }
}
Output
Element at index 0: 11.1
Element at index 1: 11.2
Element at index 2: 11.3
Element at index 3: 12.1
Element at index 4: 12.2
Element at index 5: 12.3
Element at index 6: 13.1
Element at index 7: 13.2
Element at index 8: 13.3
Element at index 9: 14.1
ArrayLoopDemo.java
class ArrayLoopDemo
{
    public static void main(String[] args)
    {
        // declares an array of floats
        float[] floatArray;

        // allocates memory for 10 floats
        floatArray = new float[10];

        // initialize first element
        floatArray[0] = 11.1f;
        // initialize second element
        floatArray[1] = 11.2f;
        // and so forth
        floatArray[2] = 11.3f;
        floatArray[3] = 12.1f;
        floatArray[4] = 12.2f;
        floatArray[5] = 12.3f;
        floatArray[6] = 13.1f;
        floatArray[7] = 13.2f;
        floatArray[8] = 13.3f;
        floatArray[9] = 14.1f;

        System.out.println("Using For loop get each element from floatArray\n");
        
        /*
         * Using For loop get all elements from floatArray
         */
        for (int i = 0; i < floatArray.length; i++)
        {
            System.out.println("Element at index " + i + " : " + floatArray[i]);
        }

    }
}
Output
Using For loop get each element from floatArray

Element at index 0 : 11.1
Element at index 1 : 11.2
Element at index 2 : 11.3
Element at index 3 : 12.1
Element at index 4 : 12.2
Element at index 5 : 12.3
Element at index 6 : 13.1
Element at index 7 : 13.2
Element at index 8 : 13.3
Element at index 9 : 14.1
To Download ArrayDemoFloatApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoFloatApp.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

    Google+ Followers

    Google+ Badge