Don't like ads? PRO users don't see any ads ;-)
Guest

Reverse an array of strings

By: a guest on Aug 10th, 2012  |  syntax: Java  |  size: 0.33 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Reverse {
  2.  
  3.         public static void main(String[] args) {
  4.                
  5.                 String[] list = new String[] {"One", "Two", "Three", "Four", "Five"};
  6.                 int N = list.length;
  7.                 for (int i = 0; i < N/2; i++)
  8.                 {
  9.                         String temp = list[i];
  10.                         list[i] = list[N-1-i];
  11.                         list[N-i-1] = temp;
  12.                         System.out.println(list[i]);
  13.                 }
  14.                
  15.         }
  16. }