Write a program in Java to input two integer numbers in the variables A and B. Swap the values of the variables without using a third variable.
Answers
Answered by
14
import java.util*;
class SwapingValues
{
public static void main(String args[ ] )
{
Scanner obj= new Scanner (System.in);
int A,B;
System.out.println("Enter a number");
A=obj.nextInt( );
System.out.println("Enter a number");
B=obj.nextInt( );
A=A+B;
B=A-B;
A=A-B;
System.out.println("Swapped Values are");
System.out.println(A);
System.out.println(B);
}
}
class SwapingValues
{
public static void main(String args[ ] )
{
Scanner obj= new Scanner (System.in);
int A,B;
System.out.println("Enter a number");
A=obj.nextInt( );
System.out.println("Enter a number");
B=obj.nextInt( );
A=A+B;
B=A-B;
A=A-B;
System.out.println("Swapped Values are");
System.out.println(A);
System.out.println(B);
}
}
hiramani7080:
if my answer is correct and satisfactory then make it a brainliest question
Answered by
3
this is the relevant answer
Attachments:
Similar questions