We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents dbb41ce + 2657c4a commit ae01ff7Copy full SHA for ae01ff7
1 file changed
Basic Codes/Swapnum.java
@@ -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