Examveda
Examveda

What is the result of the expression 3 << 2 in Java?

A. 6

B. 9

C. 8

D. 12

Answer: Option C

Solution(By Examveda Team)

Understanding the << operator:
In Java, the '<<' operator is a bitwise left-shift operator.
It takes two operands: the number to shift (on the left) and the number of positions to shift (on the right).

How it works:
The left-shift operator moves the bits of the left operand to the left by the number of positions specified by the right operand.
Each shift to the left is equivalent to multiplying by 2.

Example: 3 << 2
Let's break down 3 << 2:
1. The number 3 in binary is 0011.
2. Shifting the bits two positions to the left gives us 1100.
3. The binary number 1100 is equal to 12 in decimal.

Therefore:
The result of the expression 3 << 2 in Java is 12.

This Question Belongs to Java Program >> Operators

Join The Discussion

Comments ( 3 )

  1. Nikita Doongarwal
    Nikita Doongarwal :
    3 months ago

    Correct answer is 12.

  2. CHANDRAPRAKASH PRAJAPAT
    CHANDRAPRAKASH PRAJAPAT :
    1 year ago

    12 is correct answer

  3. Shaik Jareena
    Shaik Jareena :
    1 year ago

    12

Related Questions on Operators