write a program in Java to interchange the value of a and b with out using 3rd variable .. the program must be user friendly..
9th class icse
the best answer will b marked as brainliest
Answers
Answered by
0
import java.util.Scanner;
class Brainly
{
public static void main(String[] args)
{
int a, b;
Scanner demo = new Scanner(System.in);
System.out.println("Enter the 1st value");
a = demo.nextInt();
System.out.println("Enter the 2nd value");
b = demo.nextInt();
System.out.println(" ");
System.out.println("The result after swapping is:");
System.out.println(" ");
a = a + b;
b = a - b;
a = a - b;
System.out.println("The value of a is : "+a);
System.out.println("The value of b is : "+b);
}
Output:
Enter the value of a:
10
Enter the value of b:
20
The result after swapping is:
The value of a : 20
The value of b : 10.
Hope this helps!
class Brainly
{
public static void main(String[] args)
{
int a, b;
Scanner demo = new Scanner(System.in);
System.out.println("Enter the 1st value");
a = demo.nextInt();
System.out.println("Enter the 2nd value");
b = demo.nextInt();
System.out.println(" ");
System.out.println("The result after swapping is:");
System.out.println(" ");
a = a + b;
b = a - b;
a = a - b;
System.out.println("The value of a is : "+a);
System.out.println("The value of b is : "+b);
}
Output:
Enter the value of a:
10
Enter the value of b:
20
The result after swapping is:
The value of a : 20
The value of b : 10.
Hope this helps!
siddhartharao77:
:-)
Similar questions
Social Sciences,
7 months ago
Geography,
7 months ago
Political Science,
1 year ago
Science,
1 year ago