Java Program to swap two numbers without using third (temporary)
variable
Program :
Class Swap{
public static void main(String args[]){
int n1,n2;
n1=2;
n2=3;
n2=3;
System.out.println(“Before swap n1=”+n1 +”\nn2=”+n2);
n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
System.out.println(“After swap n1=”+n1 +”\nn2=”+n2);
}}
No comments:
Post a Comment