This is a Java Program to Multiply given Number by 4 using Bitwise Operators.
Enter the number you wish to multiply as input. After that we use left shift by 2 to multiply given input by four and hence get the output.
Here is the source code of the Java Program to Multiply given Number by 4 using Bitwise Operators. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner;
public class Multiply_Bitwise
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number:");
n = s.nextInt();
int mul = n << 2;
System.out.println("Answer:"+mul);
}
}
Output:
$ javac Multiply_Bitwise.java $ java Multiply_Bitwise Enter the number:5 Answer:20
Sanfoundry Global Education & Learning Series - 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Check Programming Books
- Practice BCA MCQs
- Practice Information Technology MCQs
- Check Java Books
- Practice Programming MCQs