Last active
October 31, 2017 06:55
-
-
Save mkdika/02cadbfeb9a867e0604674ca585b2e37 to your computer and use it in GitHub Desktop.
For vs For Each
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ArrayForEach { | |
| public static void main(String[] args) { | |
| int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
| // using regular FOR | |
| for (int i = arr.length-1 ; i >= 0 ; i--) { | |
| System.out.print(arr[i] + " "); | |
| } | |
| System.out.println(""); | |
| // using FOR EACH | |
| int e=0; | |
| for (int nilai : arr) { | |
| System.out.print(nilai + " "); | |
| e++; | |
| } | |
| System.out.println(e); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment