Swapping of Two Number with or without third variable in - JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Swapping of Two Number with or without third variable in - JAVA

Write a program Swapping Two Number with or without third variable
public class Swapping {
    public static void main(String[] args) {
        int x=5;
        int y=8;
        int temp;
        System.out.print("Before Swapping \n"+x+"\n"+y);
        System.out.println("\n"+"After Swapping");
        temp=x;
        x=y;
        y=temp;
        System.out.print(x+"\n"+y);
}
}
Output : 
swapping









without a 3rd variable
public class Swapping {
    public static void main(String[] args) {
        int x=5;
        int y=6;
        System.out.print("Before Swapping \n"+x+"\n"+y);
        System.out.println("\n"+"After Swapping");
        x=x+y;
        y=x-y;
        x=x-y;
        System.out.print(x+"\n"+y);
}

}
Output : 



       



Click to next or Start with your Choice
-Important Programs for Freshers
Sorting and Searching Programs
Learn Pattern Programs 
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!
Learn with us | HTML | CSS | Java Script | Bootstrap | JAVA | ADV JAVA | MySQL | GIT | Data Structure

No comments:

Pages