Type Here to Get Search Results !

Swap two variables a and b using java.

0

 Swap two variables a and b using java.

Solution of swapping two variables using java.

Problem Statement :-

Write a program to Swap two Variables a and b

Input

a=3 , b=4

Output

a=4, b=3


Solution :- 

import java.util.*;
public class Main
{
    public static void swap(int a,int b)
    {
        /* Write your code inside this block*/
        
        
        int temp = a;
        a = b;
        b = temp;
       
       
        /* Do not change the code beyond this point*/
        System.out.println("a value is = "+a);
        System.out.println("b value is = "+b);
    
    }
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        swap(a,b);
    }
}

Post a Comment

0 Comments