write a program to input a two number and swap them without using third variable sample input a=20, b=34; output a=34, b=20;
Answers
Answered by
1
Answer:
import java.util.Scanner;
public class KboatNumberSwap
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter two unequal numbers");
System.out.print("Enter first number: ");
int a = in.nextInt();
System.out.print("Enter second number: ");
int b = in.nextInt();
a = a + b;
b = a - b;
a = a - b;
System.out.println("a = " + a + " b = " + b);
}
}
Similar questions