Write a program in Java to input two numbers. Display the numbers after swapping them without using the third variable.
Answers
Answered by
6
public static void main(String[] args) {
int x, y, t;// x and y are to swap
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of X and Y");
x = sc.nextInt();
y = sc.nextInt();
System.out.println("before swapping numbers: "+x +" "+ y);
/*swapping */
x,y = y,x;
System.out.println("After swapping: "+x +" " + y);
System.out.println( );
}
}
Similar questions