Skip to main content

Java Program to Swap Two Numbers

In this program, you'll learn two techniques to swap two numbers in Java. The first one uses a temporary variable for swapping, while the second one doesn't use any temporary variables.

To understand this example, you should have knowledge of the following Java programming topics:

  1. Basics of Java 
  2. Java Operators 
  3. Java Data types 


Program with Temp Variable :





The output of the program is :

before swapping
value of a:5
value of b:10
after swapping
value of a:10
value of b:5


Program without temp variable : 



the output of the above program will be:

before swapping
value of first:5
value of second:10
after swapping
value of first:10
value of second:5



Follow my session on youtube : 







Comments

Popular posts from this blog

How to Write Test Cases in Manual Testing

Test Cases document: Test cases play important role during the application testing in software testing. Where each requirement is break down into multiple test scenarios and then after test cases.  here is the test case template, which is being followed by current software testing domain.  High level information:  Test Cases Break down based in the requirement.  For detail Explanation: refer the below video

How to write the defect report in software testing

 Defect report: In software testing its most important to find defects and let developer know about the defect. during this process of identifying the defect and reporting we need to follow some standard templates to report.  here is defect report template:  Refer the video for details: