import java.util.Scanner;
class SwappingWithThird
{
public static void main(String san[])
{
int firstNumber,secondNumber,temp;
Scanner in=new Scanner(System.in);// for receiving input from user
System.out.println("Enter the first number:");
firstNumber=in.nextInt();// get input one
System.out.println("Enter the second Number :");
secondNumber=in.nextInt(); // get input two
System.out.println("Before Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
temp=firstNumber;
firstNumber=secondNumber;
secondNumber=firstNumber;
System.out.println("After Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
}
}
OUTPUT:
Enter the first number:
6
Enter the second Number :
7
Before Swapping two variables FirstNumber : 6 Second Number 7
After Swapping two variables FirstNumber : 7 Second Number 7
class SwappingWithThird
{
public static void main(String san[])
{
int firstNumber,secondNumber,temp;
Scanner in=new Scanner(System.in);// for receiving input from user
System.out.println("Enter the first number:");
firstNumber=in.nextInt();// get input one
System.out.println("Enter the second Number :");
secondNumber=in.nextInt(); // get input two
System.out.println("Before Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
temp=firstNumber;
firstNumber=secondNumber;
secondNumber=firstNumber;
System.out.println("After Swapping two variables FirstNumber : " +firstNumber +" Second Number " +secondNumber);
}
}
OUTPUT:
Enter the first number:
6
Enter the second Number :
7
Before Swapping two variables FirstNumber : 6 Second Number 7
After Swapping two variables FirstNumber : 7 Second Number 7