Program to swap two numbers.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram


					import java.util.Scanner;  
public class Swap_With 
    public static void main(String[] args) 
       int a, b, temp;// a and b are to swap   
       Scanner sc = new Scanner(;  
       System.out.println("Enter the value of a and b");  
       a = sc.nextInt();  
       b = sc.nextInt();  
       System.out.println("before swapping numbers: Value of a: "+a +" Value of b:  "+ b);  
       /*swapping */  
       temp = a;  
       a = b;  
       b = temp;  
       System.out.println("After swapping: Value of a: "+a +" Value of b:  "+ b);  
       System.out.println( );  


Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *