Q:

Write a Java Program to Swap two numbers without using third variable

0

Write a Java Program to Swap two numbers without using third variable

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

SOURCE CODE : 

import java.util.Scanner;
class Swapnumber 
{
 public static void main(String[] args) 
 {
 int a, b;
 Scanner s=new Scanner(System.in);
 System.out.println("Enter Value in a :");
 a=s.nextInt();
 System.out.println("Enter Value in b :");
 b=s.nextInt();
 a=a+b;
 b=a-b;
 a=a-b;
 System.out.println("Values in a:" +a);
 System.out.println("Values in b:" +b);
 }
}

OUTPUT ::

Enter Value in a :
5
Enter Value in b :
2
Value in a : 2
Value in b : 5

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now