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?

2

1 Answer 1

4

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

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

Sign up to request clarification or add additional context in comments.

3 Comments

sir why is it possible loss of precision.?
@Hello23 Where do you see possible loss of precision?
thank you sir its already working..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.