Monday 26 October 2015

Java Tutorial : Java Array (Create, initialize, access an array)


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

Click the below Image to Enlarge
Java Tutorial : Java Array (Create, initialize, access an array)
Java Tutorial : Java Array (Create, initialize, access an array)

ArrayDemo1.java
class ArrayDemo1
{
    public static void main(String[] args)
    {
        int[] intArray = new int[5];

        // initialize first element
        intArray[0] = 10;
        // initialize second element
        intArray[1] = 20;
        // and so forth
        intArray[2] = 30;
        intArray[3] = 40;
        intArray[4] = 50;

        int i = 0;
        for (int element : intArray)
        {
            System.out.println("Element at Index " + i + " : " + element);
            ++i;
        }
    }
}
Output
Element at Index 0 : 10
Element at Index 1 : 20
Element at Index 2 : 30
Element at Index 3 : 40
Element at Index 4 : 50
ArrayDemo2.java
public class ArrayDemo2
{
    public static void main(String[] args)
    {
        int[] intArray =
        { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };

        int i = 0;
        for (int element : intArray)
        {
            System.out.println("Element at Index " + i + " : " + element);
            ++i;
        }

    }
}
Output
Element at Index 0 : 10
Element at Index 1 : 20
Element at Index 2 : 30
Element at Index 3 : 40
Element at Index 4 : 50
Element at Index 5 : 60
Element at Index 6 : 70
Element at Index 7 : 80
Element at Index 8 : 90
Element at Index 9 : 100
To Download ArrayDemoCreateInitializeApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoCreateInitializeApp.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