Normal swapping
public class Swap {
public static void main(String[] args) {
int a =90;
int b =50;
a = a+b;
b = a-b;
a =a-b;
System.out.println("A value is "+a);
System.out.println("B value is "+b);
}
}
Swapping through method
public class Swap
{
public static void m1(int a,int b)
{
int x= a;
a=b;
System.out.println("The nassigned value of a is--->"+a);
System.out.println("The nassigned value of b is--->"+b);
a=x;
System.out.println("Swaped value of a to b is-->"+a);
System.out.println("Swaped value of b to a is-->"+b);
}
public static void main(String[] args) {
m1(10, 20);
}
}
public class Swap {
public static void main(String[] args) {
int a =90;
int b =50;
a = a+b;
b = a-b;
a =a-b;
System.out.println("A value is "+a);
System.out.println("B value is "+b);
}
}
Swapping through method
public class Swap
{
public static void m1(int a,int b)
{
int x= a;
a=b;
System.out.println("The nassigned value of a is--->"+a);
System.out.println("The nassigned value of b is--->"+b);
a=x;
System.out.println("Swaped value of a to b is-->"+a);
System.out.println("Swaped value of b to a is-->"+b);
}
public static void main(String[] args) {
m1(10, 20);
}
}
No comments:
Post a Comment