Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Latihan3 {
- public static <T> void swap(T a[], int i, int j) {
- if (i < a.length & j < a.length) {
- T x = a[i];
- a[i] = a[j];
- a[j] = x;
- }
- }
- public static <T> void print(T x[]) {
- for (T y : x) {
- System.out.println(y.toString());
- }
- }
- public static void main(String[] args) {
- Integer[] i = {1, 2, 3, 4, 5};
- System.out.println("Sebelum\n");
- print(i);
- System.out.println();
- swap(i, 0, 2);
- System.out.println("Sesudah\n");
- print(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment