Swap Two Number 5 Way ||How to swap two digit in 5 way|| Er prince kumar ojha|| Swap the number
===================================
1.Write a Java program to swap two numbers using bitwise operator.
package BasicQuestionInJava;
import java.util.Scanner;
public class SwapeTwoNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter First No:");
int a=sc.nextInt();
System.out.print("Enter Second No:");
int b=sc.nextInt();
//Swape the two number using temporary variable
int temp=a;
a=b;
b=temp;
System.out.print(" First No:"+a);
System.out.print("\nSecond No:"+b);
}
}
/*Output is:
Enter First No:10
Enter Second No:20
First No:20
Second No:10
*/
================================================================
2.package BasicQuestionInJava;
import java.util.Scanner;
public class SwapeTwoNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter First No:");
int a=sc.nextInt();
System.out.print("Enter Second No:");
int b=sc.nextInt();
//Swape the two number without using temp variable
//a=10, b=20
a=a+b;
b=a-b;
a=a-b;
System.out.print(" First No:"+a);
System.out.print("\nSecond No:"+b);
}
}
/*Output is:
Enter First No:10
Enter Second No:20
First No:20
Second No:10*/
=================================================================
3.package BasicQuestionInJava;
import java.util.Scanner;
public class SwapeTwoNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter First No:");
int a=sc.nextInt();
System.out.print("Enter Second No:");
int b=sc.nextInt();
//Swape the two number using the BitWise Operator
a=a^b;
b=a^b;
a=a^b;
System.out.print(" First No:"+a);
System.out.print("\nSecond No:"+b);
}
}
/*Output is:
Enter First No:10
Enter Second No:20
First No:20
Second No:10*/
================================================================
4.package BasicQuestionInJava;
import java.util.Scanner;
public class SwapeTwoNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter First No:");
int a=sc.nextInt();
System.out.print("Enter Second No:");
int b=sc.nextInt();
//Swape the two number using the Division Operator
a=a*b;
b=a/b;
a=a/b;
System.out.print(" First No:"+a);
System.out.print("\nSecond No:"+b);
}
}
/*Output is:
Enter First No:10
Enter Second No:20
First No:20
Second No:10*/
=======================================================
5.package BasicQuestionInJava;
import java.util.Scanner;
public class SwapeTwoNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter First No:");
int a=sc.nextInt();
System.out.print("Enter Second No:");
int b=sc.nextInt();
//Swap the two number using the Division Operator
a=a*b;
b=a/b;
a=a/b;
System.out.print(" First No:"+a);
System.out.print("\nSecond No:"+b);
}
}
/*Output is:
Enter First No:10
Enter Second No:20
First No:20
Second No:10*/
=======================================================
I am going to introduce coading practic of the programming of language in java
How to write a program to print the logical coading practive of given of the
language. There is a way to improved the coading standered of coading practice.
Comments
Post a Comment