Code :
import java.util.Scanner;
class Swapping {
public static void main (String args[])
{
int FirstNumber, SecondNumber, Temp;
Scanner sobject=new Scanner(System.in);
System.out.println("Enter Two Numbers: ");
FirstNumber = sobject.nextInt();
SecondNumber = sobject.nextInt();
System.out.println("Before swapping Method: \n FirstNumber = "+FirstNumber +"\n SecondNumber = "+SecondNumber);
Temp = FirstNumber;
FirstNumber = SecondNumber;
SecondNumber = Temp;
System.out.println("After swapping Method: \n FirstNumber = "+FirstNumber +"\n SecondNumber = "+SecondNumber);
}
}
Output :
Enter Two Numbers:
5
3
Before swapping Method:
FirstNumber = 5
SecondNumber = 3
After swapping Method:
FirstNumber = 3
SecondNumber = 5
IDE Used To Test This Code : Dr Java
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.
import java.util.Scanner;
class Swapping {
public static void main (String args[])
{
int FirstNumber, SecondNumber, Temp;
Scanner sobject=new Scanner(System.in);
System.out.println("Enter Two Numbers: ");
FirstNumber = sobject.nextInt();
SecondNumber = sobject.nextInt();
System.out.println("Before swapping Method: \n FirstNumber = "+FirstNumber +"\n SecondNumber = "+SecondNumber);
Temp = FirstNumber;
FirstNumber = SecondNumber;
SecondNumber = Temp;
System.out.println("After swapping Method: \n FirstNumber = "+FirstNumber +"\n SecondNumber = "+SecondNumber);
}
}
Output :
Enter Two Numbers:
5
3
Before swapping Method:
FirstNumber = 5
SecondNumber = 3
After swapping Method:
FirstNumber = 3
SecondNumber = 5
IDE Used To Test This Code : Dr Java
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.
Post a Comment