import java.util.Scanner;
class SwappingNoThird
{
public static void main(String san[])
{
int firstNumber,secondNumber;
Scanner in=new Scanner(System.in);
System.out.println("Enter the first number:");
firstNumber=in.nextInt();
System.out.println("Enter the second Number :");
secondNumber=in.nextInt();
System.out.println("Before Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
firstNumber=firstNumber+secondNumber;
secondNumber=firstNumber-secondNumber;
firstNumber=firstNumber-secondNumber;
System.out.println("After Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
}
}
OUTPUT:
Enter the first number:
76
Enter the second Number :
67
Before Swapping two variables FirstNumber : 76 Second Number 67
After Swapping two variables FirstNumber : 67 Second Number 76
class SwappingNoThird
{
public static void main(String san[])
{
int firstNumber,secondNumber;
Scanner in=new Scanner(System.in);
System.out.println("Enter the first number:");
firstNumber=in.nextInt();
System.out.println("Enter the second Number :");
secondNumber=in.nextInt();
System.out.println("Before Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
firstNumber=firstNumber+secondNumber;
secondNumber=firstNumber-secondNumber;
firstNumber=firstNumber-secondNumber;
System.out.println("After Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
}
}
OUTPUT:
Enter the first number:
76
Enter the second Number :
67
Before Swapping two variables FirstNumber : 76 Second Number 67
After Swapping two variables FirstNumber : 67 Second Number 76