package javabox;
public class SwapExample {
public static void main(String a[]){
int x = 30;
int y = 40;
int temp;
System.out.println("Before swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
temp = x;
x = y;
y = temp;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}
Output -
Before swap:
x value: 30
y value: 40
After swap:
x value: 40
y value: 30
public class SwapExample {
public static void main(String a[]){
int x = 30;
int y = 40;
int temp;
System.out.println("Before swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
temp = x;
x = y;
y = temp;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}
Output -
Before swap:
x value: 30
y value: 40
After swap:
x value: 40
y value: 30
No comments:
Post a Comment