Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

error while using math.pow in java code

i have a java code for finding out netsalary . I keep Getting "bad operand type for binary operator ' / '" error . The Line goes like this

netSalary = Double.parseDouble(principle2*rate2/12*Math.pow(rate2/12+1))/(Double.parseDouble(Math.pow(rate2/12+1)-1));

Could this be solved . Thanks in advance!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

It should be commas you use, not slashes.

Math.pow(rate2/12+1) should syntactically be in the form of Math.pow(x,y) where both x and y are doubles. The first arg is the base, and second arg is the index you're raising it to. As the comment below mentioned, it's difficult to understand what you're trying to achieve, and you'll have to substitute x and y for the correct values - make sure they're of type double (you cannot use, for example, 12+1 as a parameter because it is an integer). If it is an integer, then type cast it using (double) in front of the value.

You also do not need to parseDouble everywhere since Math.pow will return double values anyways; it is redundant.

I agree with the comment above; please read the javadocs for any problems you're having with a method before posting here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...