Java Program to print an array

0


In this tutorial we will see how can we print an array in java . For this we have written two codes.


class HindiCodingCommunity {

public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};

for (int i=0;i<array.length;i++) {
System.out.println(array[i]);
}
}

}

In this we have created the variable i and accessing all the elements of the array one by one and printing them.



class HindiCodingCommunity {

public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};

for (int i: array) {
System.out.println(i);
}
}
}



Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !