Swap Reference Java Jeliot

jeliot.io import .*;

public class Numbers {
     public Num (int x) {/ / constructor
         a = x;
     }
     public static void swap (Num a, Num b) {
          int temp;
          temp = a.a;
          a.a = b.a;
          b.a = temp;
     }
     public final void output () {
          System.out.println ("number:" + a);
     }
     private int a;

public static void main () {
        System.out.println ("\ nUsing class \ n");
        Numbers x1 = new Numbers (5);
        Numbers y1 = new Numbers (6);
        x1.output ();
        y1.output ();
        swap (x1, y1);
        System.out.println ("\ nAfter swap disposable class: \ n");
        x1.output ();
        y1.output ();
    }
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s