0

why is it that this is wrong? i input the heightL as 2 the output must be 4 but there is something wrong

class He{
public static void main(String[] args)
{
    int heightL=2;
    int a = 9;
    System.out.println(Math.abs(a));
    System.out.println(2^(heightL));
}
}

why is it that the output in the second part is 0?

Hello23
  • 37
  • 2
  • 8

1 Answers1

4

^ is not an exponent operator, it's bit-wise XOR (and 2 XOR 2 is 0).

For exponent, use Math.pow(2,heightL).

Eran
  • 387,369
  • 54
  • 702
  • 768