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) |
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; } } }
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
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; } } }
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
https://sites.google.com/site/javaee4321/java/ArrayDemoCreateInitializeApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment