Sunday 16 August 2015

WAP in java to swap 2 nos without using 3rd variable.

//Swap 2 nos without the use of 3rd variable.

import java.util.Scanner;

public class Swap {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a,b;

System.out.println("Enter 2 nos:");
a=sc.nextInt();
b=sc.nextInt();

System.out.println("Before Swapping...a="+a+" b="+b);
a=a+b;
b=a-b;
a=a-b;

System.out.println("After swapping...a="+a+" b="+b);
}
}

1 comment:

  1. NJ casinos set to offer sports betting to their customers in May
    A total of 20 mobile-optimized NJ 용인 출장샵 casinos and 구미 출장안마 sports betting terminals are set to offer 군포 출장샵 sports 서귀포 출장마사지 betting for 밀양 출장샵 customers in MGM National Harbor Resort and Casino

    ReplyDelete