-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

2
  • what type weightsarray has? Ans what error the code gives you? Commented Mar 14, 2019 at 17:35
  • By the way, it doesn't look like conversion from arrayList to array. See here stackoverflow.com/questions/7969023/from-arraylist-to-array Commented Mar 14, 2019 at 17:37

1 Answer 1

0

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

if(character == '1') {
    rhs += weightsarray[i];
} else {
    lhs += weightsarray[i];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.