Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Write a series of Java statements that interchange the values of two numeric variables without using a third variable. Save the class as InterchangeNumbers.java.

Here is a description to help... If you have two variables which have values 3 and 7.

first variable equals the sum (10)

second variable equals the sum less the current value of the second (10-7=3)

Now we have the first variable into the second variable.

first variable equals the first variable less the second variable (10-3=7)

That's it! Have switched the value of the variables without using a third variable. Now implement this in Java :-)

What I have tried:

i tried to code it but i am not understanding it.
Posted
Updated 27-Sep-17 23:12pm
v2
Comments
Afzaal Ahmad Zeeshan 27-Sep-17 20:34pm    
What did you try, paste that code here.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
Read the instructions carefully and try them by hand - you'll get the idea if you just use two numbers written on a piece of paper. Once you see what he is going on about, it'll be pretty obvious what you need to code.

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900