Friday 23 October 2015

Java Tutorial : Java Array (long values)


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

Click the below Image to Enlarge
Java Tutorial : Java Array (long values)
ArrayDemo.java
class ArrayDemo
{
    public static void main(String[] args)
    {
        // declares an array of longs and allocates memory for 10 longs
        long[] longArray = new long[10];

        // initialize first element
        longArray[0] = 10000L;
        // initialize second element
        longArray[1] = 30000L;
        // and so forth
        longArray[2] = 35000L;
        longArray[3] = 40000L;
        longArray[4] = 45000L;
        longArray[5] = 42000L;
        longArray[6] = 50000L;
        longArray[7] = 60000L;
        longArray[8] = 90000L;
        longArray[9] = 80000L;

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

    }
}
Output
Element at index 0: 10000
Element at index 1: 30000
Element at index 2: 35000
Element at index 3: 40000
Element at index 4: 45000
Element at index 5: 42000
Element at index 6: 50000
Element at index 7: 60000
Element at index 8: 90000
Element at index 9: 80000
ArrayLoopDemo.java
class ArrayLoopDemo
{
    public static void main(String[] args)
    {
        // declares an array of longs and allocates memory for 10 longs
        long[] longArray = new long[10];

        // initialize first element
        longArray[0] = 10000L;
        // initialize second element
        longArray[1] = 30000L;
        // and so forth
        longArray[2] = 35000L;
        longArray[3] = 40000L;
        longArray[4] = 45000L;
        longArray[5] = 42000L;
        longArray[6] = 50000L;
        longArray[7] = 60000L;
        longArray[8] = 90000L;
        longArray[9] = 80000L;

        System.out
                .println("Using for loop getting each element "
                        + "from the longArray\n");

        /*
         * Using For loop get all elements from longArray
         */
        for (int i = 0; i < longArray.length; i++)
        {
            long longValue = longArray[i];
            System.out.println("Element at index " + i + " : " + longValue);

        }
    }
}
Output
Using for loop getting each element from the longArray

Element at index 0 : 10000
Element at index 1 : 30000
Element at index 2 : 35000
Element at index 3 : 40000
Element at index 4 : 45000
Element at index 5 : 42000
Element at index 6 : 50000
Element at index 7 : 60000
Element at index 8 : 90000
Element at index 9 : 80000
To Download ArrayDemoLongApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoLongApp.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