Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create swap_two_num_without_using_temp_variable.java #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions swap_two_num_without_using_temp_variable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.*;
class SwapTwo{
public static void main(String a[])
{
System.out.println("Enter the value of x and y");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println("before swapping numbers: "+a +" "+ b);
/*Swapping*/
a = a + b;
b = a - b;
a = a - b;
System.out.println("After swapping: "+a +" " + b);
}
}