The absolutes variable represents a number. The sign attempts to convert "-" into a number "++" when "negative number" is "positive number". We're going to solve the task of adding all the variables that we changed.
a[i] = absolutes[i].unaryMinus()
In this sentence, Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
An error appears.
Can I know which part is wrong?
val absolutes = intArrayOf(4,7,12)
val sign = arrayOf(true,false,true)
val a = intArrayOf(0)
for (i in absolutes.indices){
if (!sign[i]) {
a[i] = absolutes[i].unaryMinus()
}
}
val result = a.sum()
Log.d(logTag, "onCreate is called result = $result")