Computer Science, asked by dhruv909982, 1 year ago

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

Answers

Answered by nitish8089
1
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);
}
}
Answered by Yogesh0
0
int a =5 , b =6 ;

a = a + b ;
b = a - b ;
a = a - b ;
Similar questions