1.

Write a java program to swap 2 numbers without using the temporary variables

Answer»

Check the program mainly three METHOD i know to solve this: multiplication method is used for only positive number TRY yourelf
and third is BITWISE OPERATOR..
import java.util.Scanner;
public class Program
{
public static void main(STRING[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();// enter a no.
int b=sc.nextInt();//enter a no.
System.out.println("value of a you enter before swap is a:"+a);
System.out.println("value of b you enter before swap is b:"+b);
a+=b;
b=a-b;
a=a-b;
System.out.println("value of a after swap is a:"+a);
System.out.println("value of b after swap is a:"+b);
}
}



Discussion

No Comment Found