Computer Applications
Write a program to interchange the value of two numbers without using the third variable.
Java
Java Intro
92 Likes
Answer
public class KboatSwap
{
public static void swapNumbers(int a, int b) {
System.out.println("The numbers are:");
System.out.println("a=" + a + " b=" + b);
a = a + b;
b = a - b;
a = a - b;
System.out.println("The numbers after interchange:");
System.out.println("a=" + a + " b=" + b);
}
}
Output
![BlueJ output of Write a program to interchange the value of two numbers without using the third variable. BlueJ output of Write a program to interchange the value of two numbers without using the third variable.](https://cdn1.knowledgeboat.com/img/lgx8/c5-java-p5.jpg)
Answered By
35 Likes