Swapping of two numbers - Coder's point

Saturday, June 1, 2019

Swapping of two numbers


import java.util.*;  
 public class SwapNum  
 {  
  public static void main(String[]args)  
   {  
    Scanner in = new Scanner(System.in);  
    System.out.println("Enter two numbers :");  
    int x=in.nextInt();  
    int y=in.nextInt();  
    System.out.println("Number before swapping");  
    System.out.println("X= "+x);  
    System.out.println("Y= "+y);  
    int temp;  
    temp=x;  
    x=y;  
    y=temp;  
    System.out.println("Number after swapping");  
    System.out.println("X= "+x);  
    System.out.println("Y= "+y);  
   }  
 }  

OUTPUT:

Enter two numbers :
8
9
Number before swapping
X= 8
Y= 9
Number after swapping
X= 9
Y= 8

No comments:

Post a Comment