#Why does this code give me an error?
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
public class main {
public static int [] invert(int [] array) {
for (int number : invert) {
new _int .add(number * - 1);
}
return new _int [] {
};
}
}
Helper please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
The issue in the code is that the for loop is incorrectly attempting to iterate over the array 'invert' instead of 'array'. To fix this, change 'for (int number : invert)' to 'for (int number : array)'.
Useful links:
It's an array and not a list. Therefore it has no methods like 'add'
ahhh
You have three different names here
also new_int and invert doesnt exist here
its on codewars
i just copied the code
It's mostly nonsense.
well thats what i got
Invert, for a number, means find it's reciprocal. And doing that on an int is going to end poorly.