-4
 public double getRandKg(double[] value)
{
    double min = 0.0;
    double max = 0.0;

    value * 0.90 = min;          <------ this is where it says bad operand
    value * 1.10 = max;                   types for binary operator '*'
    Random r = new Random();              first type double[] second type double

    double randomValue = min + (((max-min)+1) * r.nextDouble());
    return randomValue;                                                                         //

}

It's late and maybe I just can't think straight. It's just saying I can't multiply a double[] by a double?

P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37
  • Which language are you using? – devnull Mar 17 '14 at 11:38
  • 4
    Yeah. Furthermore, you can't have an expression in the left side of an assignment – Karura91 Mar 17 '14 at 11:38
  • 7
    This question appears to be off-topic because there are too many problems to sort out. The OP needs to refer to a beginner tutorial before setting off to write code. – devnull Mar 17 '14 at 11:40
  • I think you need to get an introductory book on Java, because this code is all kinds of `what?`. Could you explain what your program is supposed to do? EDIT: Well, now I'm confused, because from this post: http://stackoverflow.com/questions/22433375/saturday-night-java-fun-with-2d-arrays-and-reading-a-text-based-tab-delimited-f it seems that OP is competent with Java. It must have been one crazy night or something... – Chris Middleton Mar 17 '14 at 11:40
  • This is just a method to return a random double number in a range of 10% of what is passed. – user3414479 Mar 17 '14 at 11:43
  • In that case, you want to find the min/max of the array first, and then using those results, multiply by 0.9 and 1.1 to get the 10%-adjusted min/max. I'm curious what the application of this is. – Chris Middleton Mar 17 '14 at 11:45
  • too many problems to sort out in 7 lines of code...hardly...either help or don't comment.... no one forced you to type on your keyboard. – user3414479 Mar 17 '14 at 11:48
  • its an indexed value of the array that is being passed – user3414479 Mar 17 '14 at 11:49
  • Sorry everyone...it's 5 am where I live...been up for way too long. – user3414479 Mar 17 '14 at 11:50
  • Wow... boneheaded post...i see it all now...sorry for wasting time. thanks for everyones help – user3414479 Mar 17 '14 at 11:53

2 Answers2

2

double[] is an array. How can you multiply an array of double values with a single double value?

use double[someIndex] * doubleVar to multiply with a single value, and put the expression on the right side, not the left.

anirudh
  • 4,116
  • 2
  • 20
  • 35
  • Yeah.. I thought this would work since what is being passed in the method as value is an array that has an index. i.e. avgKgNitrogen[z] is being passed in a loop for when z=0 – user3414479 Mar 17 '14 at 11:47
  • In that case, change the method definition to `public double getRandKg(double value)` – anirudh Mar 17 '14 at 11:48
  • BONEHEAD QUESTION....i get it.... Thanks for your constructive help. I feel like a total bonehead now. – user3414479 Mar 17 '14 at 11:52
0

I believe you are trying to set the values for min and max. In which case you are doing the wrong way round.

It should be:

min = value * 0.90;          
max = value * 1.10;

http://docs.oracle.com/javase/tutorial/reflect/member/fieldValues.html

--

Also you cannot multiply an array by a double. You should refer to which key=>value in the array you want to use.

For example

min = value[0] * 0.90;
min = value[0] * 0.90;

Where value[0] refers to the first array index (as arrays start from 0)

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

H H
  • 2,065
  • 1
  • 24
  • 30