Single Choice Easy

QWhich arithmetic operator is used for exponentiation in Java?

ID: #20127 Arithmetic Operators in Java 95 views
Question Info
#20127Q ID
EasyDifficulty
Arithmetic Operators in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A ^
  • B **
  • C **
  • D none o them
Correct Answer

Explanation

Java does not have a built-in exponentiation operator. The ^ symbol in Java is the bitwise XOR operator, not an exponentiation operator.


public class BitwiseXORExample {
    public static void main(String[] args) {
        // Example 1: Using ^ for bitwise XOR
        int a = 5;   // Binary: 0101
        int b = 3;   // Binary: 0011

        int result = a ^ b;  // Binary: 0110 (Decimal: 6)
        
        System.out.println("Result of bitwise XOR: " + result);

        // Example 2: Using ^ for toggling a single bit
        int num = 8;   // Binary: 1000
        int mask = 1;   // Binary: 0001

        int toggled = num ^ mask;  // Toggle the rightmost bit
        
        System.out.println("Toggled result: " + toggled);
    }
}

Share This Question

Challenge a friend or share with your study group.