How to swap two numbers in java using “*” and “/” operator

I consider that you have basic knowledge of core java and you know that how to make class in java.

Let’s start

public class SwapTwoNumbers

{

public static void main(String[] arg)

{

int a=10,b=20;

int multiply=a*b; //Here multiply a and b ,means multiply=200

int a=multiply/a; //Here multiply value is 200 and a value is 10 ,ie 200/10=20

int b=multiply/a; //Here multiply value is 200 and a value is 20 (updated value) not 10,ie 200/20=10

}

System.out.println(“a value will be=” + a + “b value will be=” +b);

}

Output:

a value will be=20

b value will be=10

sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

2 thoughts on “How to swap two numbers in java using “*” and “/” operator

  • February 18, 2019 at 3:14 pm
    Permalink

    Very useful for our interview

    Reply
    • February 18, 2019 at 4:55 pm
      Permalink

      Thanks for the visiting my website.I always try to provide the best to best.

      Reply

Leave a Reply

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