Swapping two numbers by multiplication and division
Java Program to Swap two numbers by using division and multiplication.
Input:
56 32
Output:
Swapped numbers: 32 56
import java.io.*; import java.util.*; public class temp{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.print("Enter any two numbers: "); int a = scan.nextInt(); int b = scan.nextInt(); a = a*b; b = a/b; a = a/b; System.out.println("Swapped numbers: "+String.format("%d %d",a,b)); } }
INPUT_1:
Enter any two numbers: 3 2
OUTPUT:
Swapped numbers: 2 3
INPUT_2:
Enter any two numbers: 45 50
OUTPUT:
Swapped numbers: 50 45
INPUT_3:
Enter any two numbers: 100 200
OUTPUT:
Swapped numbers: 200 100
INPUT_4:
Enter any two numbers: 100 150
OUTPUT:
Swapped numbers: 150 100
INPUT_5:
Enter any two numbers: 60 25
OUTPUT:
Swapped numbers: 25 60
ILLUSTRATION