Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import java.util.Arrays;
  2. public class Exercise2 {
  3. public static int[] reverse(int[] array) {
  4. int[] result = new int [array.length];
  5.  
  6. for (int i = 0, j = result.length - 1; i < array.length; i++, j--) {
  7. result[j] = array[i];
  8. }
  9. return result;
  10. }
  11. public static void main(String[] args) {
  12. int[] list1 = new int[] {1, 2, 3, 4, 5, 6};
  13. int[] list2 = reverse(list1);
  14.  
  15. System.out.println(Arrays.toString(list2));
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement