Java Program To Swap Two Numbers - Java Program Example

Write Java Program To Swapping Two Numbers ,In This Post We Share A Java Program Code For Swapping Two Numbers.

Program Code

package com.androidpro.in;




import
java.util.*;

public class
Main {

   
public static void main(String args[])
    {
       
int x, y, temp;
       
System.out.println("Enter x and y");
       
Scanner in = new Scanner(System.in);
       
x = in.nextInt();
       
y = in.nextInt();
       
System.out.println("Before Swapping\nx = "+x+"\ny = "+y);
       
temp = x;
       
x = y;
       
y = temp;
       
System.out.println("After Swapping\nx = "+x+"\ny = "+y);
    
}


}

 


Output

Enter x and y
4
5
Before Swapping
x = 4
y = 5

After Swapping
x = 5
y = 4
  1. Convert Binary Numbers To Decimal Numbers 
  2. Convert Number To Text Java Program 
  3. Java Program To Calculate Arithmetical Operators 
  4. Java Program To Print Current Date Day
  5. Java Program To Calculate Area Of Circle 
  6. Java Program To Calculate Area Of Rectangle

Post a Comment

0 Comments