Java Program

Object:-Write a Program to multiply given number by 4 using Bitwise Operators

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

Enter the number:5
Answer:20
 

Explanation

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.








You may also like: