ishusupah

Traverse Array Java

Jan 26th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class GeekIshu{
  2. public static void main(String[] args){
  3. int[] arr = {1100,1322,4566,3244,2333};
  4. // 0 1 2 3 4
  5.  
  6.  
  7. // Traversing = is the process of accessing each element present in collection
  8. /*
  9. 1. for - loop
  10. 2. for - each
  11. */
  12. // i=0 -> 1 -> 2 ->3 ->4 (terminated)
  13. //1. for - loop
  14.  
  15. for(int i=0; i<arr.length;i++){
  16. System.out.println(arr[i]);
  17. }
  18.  
  19. //2. for - each
  20. /* syntax
  21. for( datatype x : Collection ){
  22. // action
  23. }
  24. */
  25. System.out.println("for each");
  26. for( int x : arr){
  27. System.out.println(x);
  28. }
  29.  
  30.  
  31.  
  32. }
  33. }
Add Comment
Please, Sign In to add comment