ariestamirra

unary

Oct 8th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public class Latihan3 {
  2.  
  3.     public static <T> void swap(T a[], int i, int j) {
  4.         if (i < a.length & j < a.length) {
  5.             T x  = a[i];
  6.             a[i] = a[j];
  7.             a[j] = x;
  8.         }
  9.     }
  10.  
  11.     public static <T> void print(T x[]) {
  12.         for (T y : x) {
  13.             System.out.println(y.toString());
  14.         }
  15.     }
  16.  
  17.     public static void main(String[] args) {
  18.         Integer[] i = {1, 2, 3, 4, 5};
  19.         System.out.println("Sebelum\n");
  20.         print(i);
  21.        
  22.         System.out.println();
  23.         swap(i, 0, 2);
  24.         System.out.println("Sesudah\n");
  25.         print(i);
  26.        
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment