Skip to content

Commit ae01ff7

Browse files
Merge pull request #31 from dineshparekh11/dinesh1
Solution of swap two number
2 parents dbb41ce + 2657c4a commit ae01ff7

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Basic Codes/Swapnum.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Write a program to swap two numbers (with the help of third variable).
2+
import java.util.Scanner;
3+
4+
class Swapnum
5+
{
6+
public static void main(String args[])
7+
{
8+
int num1, num2, temp; //create temp variable for storing value
9+
System.out.println("Enter number1 and number2");
10+
Scanner in = new Scanner(System.in);
11+
12+
num1 = in.nextInt();
13+
num2 = in.nextInt();
14+
15+
System.out.println("Before Swapping\nnum1 = "+num1+"\nnum2 = "+num2); //before swap
16+
17+
temp = num1; //temp assign to num1
18+
num1 = num2;
19+
num2 = temp;
20+
21+
System.out.println("After Swapping\nnum1 = "+num1+"\nnum2 = "+num2);
22+
}
23+
}

0 commit comments

Comments
 (0)