Showing posts with label swap two numbers. Show all posts
Showing posts with label swap two numbers. Show all posts

Thursday, June 4, 2020

Write a program in java to input two number and Swap the Numbers (interchange the value) without using third variable.

3)  Write a program in java to input two number and Swap the Numbers (interchange the value) without using third variable.

public class Swaping_without_using_third_var
{
    public static void main(int a,int b)
    {
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        a = a + b;
        b = a - b;
a = a - b;
        System.out.println();
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
}


Write a program in java to input two number and Swap the Numbers (interchange the value) using third variable.

2)  Write a program in java to input two number and Swap the Numbers (interchange the value) using third variable.

public class Swaping_using_third_var
{
    public static void main(int a, int b)
    {
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        int p = a;
        a = b;
        b = p;
        System.out.println();
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
}

 jhvghvgk ;nkjn ,nkjhj