fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] myArray = { "alpha" , "beta" , "gamma" } ;
  13.  
  14. System.out.println( "------| Ascending |----------" ) ;
  15. for ( int index = 0 ; index < myArray.length ; index ++ )
  16. {
  17. System.out.println( "Index: " + index + ", Value: " + myArray[ index ] );
  18. }
  19.  
  20. System.out.println( "" ) ;
  21. System.out.println( "------| Descending |----------" ) ;
  22. for ( int index = ( myArray.length - 1 ) ; index > -1 ; index -- )
  23. {
  24. System.out.println( "Index: " + index + ", value: " + myArray[ index ] );
  25. }
  26. }
  27. }
Success #stdin #stdout 0.14s 57580KB
stdin
Standard input is empty
stdout
------|  Ascending  |----------
Index: 0, Value: alpha
Index: 1, Value: beta
Index: 2, Value: gamma

------|  Descending  |----------
Index: 2, value: gamma
Index: 1, value: beta
Index: 0, value: alpha