Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GeekIshu{
- public static void main(String[] args){
- int[] arr = {1100,1322,4566,3244,2333};
- // 0 1 2 3 4
- // Traversing = is the process of accessing each element present in collection
- /*
- 1. for - loop
- 2. for - each
- */
- // i=0 -> 1 -> 2 ->3 ->4 (terminated)
- //1. for - loop
- for(int i=0; i<arr.length;i++){
- System.out.println(arr[i]);
- }
- //2. for - each
- /* syntax
- for( datatype x : Collection ){
- // action
- }
- */
- System.out.println("for each");
- for( int x : arr){
- System.out.println(x);
- }
- }
- }
Add Comment
Please, Sign In to add comment