Computer Science, asked by kalpana6671, 1 year ago

Write a program for exchange two nos without the use of the third variable.

Answers

Answered by nitish8089
2
import java.util.Scanner;

public class Program{

public static void main(String...args){

Scanner sc=new Scanner(System.in);

int a=sc.nextInt();

int b=sc.nextInt();

System.out.println("value of a before swap: "+a+" value of b before swap: " +b);


a+=b;

b=a-b;

a=a-b;

System.out.println("value of a after swap: "+a+" value of b after swap: " +b);

}


}
Similar questions