-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSwaping.java
46 lines (36 loc) · 1.1 KB
/
Swaping.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* WAP in java to swap two integers without using third variable. The swapping
* must be done in a different method in a different class.
*/
/**
*
* @author Rahul Shyokand
*/
import java.util.Scanner;
public class Swaping
{
static int Swap()
{
int num1 , num2;
System.out.println("Enter the first number");
//Object of scanner class
Scanner scan = new Scanner(System.in);
//storing the int datatype values in num1
num1= scan.nextInt() ;
System.out.println("Enter the second number");
//storing int in num2
num2= scan.nextInt();
// logic
num1=num1+num2;
num2= num1-num2;
num1=num1-num2;
//printing data
System.out.println("First num now is " + num1);
System.out.println("Second number now is " + num2);
return 0;
}
public static void main(String arg[])
{
Swap(); //Swap Function called
}
}