Skip to content

Commit 7c9b9c2

Browse files
Solution of swap two number
1 parent dbb41ce commit 7c9b9c2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Basic Codes/Swapnum.java

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

0 commit comments

Comments
 (0)