Computer Applications
Write a program to interchange the value of two numbers without using the third variable.
Java
Java Intro
90 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
Answered By
35 Likes