Q:

Write a Java program to Swap two numbers using third variable

0

Swapping is the process of exchange the values of two variables with each other. For example variable num1 contains 1 and num2 contains 2 after swap their values are num1 contains 2 and num2 contains 1

All Answers

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

SOURCE CODE::

import java.util.*;
public class Swapnumber 
{
 public static void main(String[] args) 
 {
  int a, b, c;
  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();
  c=a;
  a=b;
  b=c;
  System.out.println("Values in a:" +a);
  System.out.println("Values in b:" +b);
 }
}

OUTPUT ::

 
Enter Value in a : 1
Enter Value in b : 2
Value in a : 2
Value in b : 1

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