Skip to main content

Swipe Number without third variable and without arithmetic operator in JAVA.

CODING:
class main{
 public static void main(String args[]){
   Swap obj1=new Swap();
   System.out.println(obj1.a + " " + obj1.b);
   obj1=new Swap(obj1);
   System.out.println(obj1.a + " " + obj1.b);
   Swap obj2=new Swap();
   System.out.println(obj2.a + " " + obj2.b);
   obj2=new Swap(obj2);
   System.out.println(obj2.a + " " + obj2.b);
  }
}
class Swap{
  int a,b;
  Swap(){
   a=10;b=20;
   }
  Swap(Swap o){
   a=o.b;
   b=o.a;
  }
}

Comments