Java program to swap two numbers

Published: 02 August 2023
on channel: The Disciplined learner
603
19

This java program swaps two numbers using a temporary variable. To swap numbers without using extra variable see another code below. Swapping using temporary or third variable
public static void main(String[] args) {
int x,y,temp;
System.out.println("Enter x and y");
Scanner in=new Scanner(System.in);
x=in.nextInt();
y=in.nextInt();
System.out.println("Before Swapping \nx = "+x+"\ny = "+y);
temp=x;
x=y;
y=temp;
System.out.println("After Swapping \nx = "+x+"\ny = "+y);
}


On this page of the site you can watch the video online Java program to swap two numbers with a duration of hours minute second in good quality, which was uploaded by the user The Disciplined learner 02 August 2023, share the link with friends and acquaintances, this video has already been watched 603 times on youtube and it was liked by 19 viewers. Enjoy your viewing!