user331570
user331570

Reputation: 49

Java Newbie can't do simple Math, operator error

Trying to do some really basic math here, but my lack of understanding of Java is causing some problems for me.


double[][] handProbability = new double[][] {{0,0,0},{0,0,0},{0,0,0}};
double[] handProbabilityTotal = new double[] {0,0,0};
double positivePot = 0;
double negativePot = 0;
int localAhead = 0;
int localTied = 1;
int localBehind = 2;
//do some stuff that adds values to handProbability and handProbabilityTotal

positivePot = (handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0));

negativePot = (handProbability[localAhead][localBehind] + (handProbability[localAhead][localTied] / 2.0) + (handProbability[localTied][localBehind] / 2.0) ) / (handProbabilityTotal[localAhead] + (handProbabilityTotal[localTied] / 2.0));

The last two lines are giving me problems (sorry for their lengthiness). Compiler Errors:


src/MyPokerClient/MyPokerClient.java:180: operator / cannot be applied to double[],double
            positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) );
                                                                                                                                                                                                                                             ^
src/MyPokerClient/MyPokerClient.java:180: operator + cannot be applied to double,
            positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) );
                                                                                                                                                                                                 ^
src/MyPokerClient/MyPokerClient.java:180: operator / cannot be applied to double,
            positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) );

Not really sure what the problem is. You shouldn't need anything special for basic math, right?

Upvotes: 1

Views: 322

Answers (3)

Sujee
Sujee

Reputation: 5145

The line before last line has the issue.

positivePot = 
   (handProbability[localBehind][localAhead] + 
   (handProbability[localBehind][localTied] / 2.0) + 
   (handProbability[localTied][localAhead] / 2.0) ) / 
   (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0));

handProbability is a two dimensional double array. So handProbability[localTied] is an array of doubles. it is not a double value. Based on your last line, I think it should be handProbabilityTotal[localTied].

Upvotes: 3

MiKo
MiKo

Reputation: 2146

Since handProbability is the multidimensional array, it's impossible to divide an array to number:

handProbability[localTied] / 2.0

Sure, it gives you the error. Fix this line. Have you probably meant handProbabilityTotal?

Upvotes: 1

Avi
Avi

Reputation: 20152

In the last part of the first line (handProbability[localTied] / 2.0) you are trying to divide an array (hardProbability[localTied]) instead of a number (one of its values).

Upvotes: 3

Related Questions