Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
836 views
in Technique[技术] by (71.8m points)

vb.net - The power operator in Java?

When I run the following Visual Basic code :

Dim b As Double
b = (2 ^ 16 - 1) * Math.Sqrt(Math.Sqrt((a / (2 ^ 8 - 1))))

(Assuming a is a double whose value is 15.0)
The result I get for b is about 32,275.

But when I run the following Java code, which is supposed to do the same as above:

double b;
b = (2 ^ 16 - 1) * Math.sqrt(Math.sqrt((a / (2 ^ 8 - 1))));

Again with a being 15, I get a much different result: about 17.

Both are solving this equation:

enter image description here

Why is this so? For what I'm working on, the Visual Basic yields result I'm looking for.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

^ is XOR operator in java. Use Math.pow(2,8) which is 2 ^ 8 in Visual Basic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...