-1

I'm trying to change my arrayList to an array but not sure how to change the

rhs += weightsarray.get[i];

In my code below, it keeps giving me errors:

if(weightsarray == null || weightsarray.length == 0)
        return -1;
    double lhs = 0.0,rhs = 0.0;
    int n = scasol.length();
    for(int i = 0; i < n; i++) {
        char character = scasol.charAt(i);
        if(character == '1') {
            rhs += weightsarray.get[i];
        } else {
            lhs += weightsarray.get(i);
        }
    }

    return(Math.abs(lhs-rhs));
}

The arraylist was where the weightsarray is now

If anyone could help that would be great, if you need any more info let me know (One of my first times using this so not really 100% sure how it works)

Cheers

The Game
  • 3
  • 1
  • what type `weightsarray` has? Ans what error the code gives you? – Ruslan Mar 14 '19 at 17:35
  • By the way, it doesn't look like conversion from arrayList to array. See here https://stackoverflow.com/questions/7969023/from-arraylist-to-array – Ruslan Mar 14 '19 at 17:37

1 Answers1

0

You're getting arrays element incorrectly, it should be like that:

if(character == '1') {
    rhs += weightsarray[i];
} else {
    lhs += weightsarray[i];
}
Andronicus
  • 25,419
  • 17
  • 47
  • 88