122k views
1 vote
Write a function negateOdds that takes a list of integers and returns a list of integers with all of the odd integers negated. negateOdds :: [Integer] -> [Integer]

example: [1,2,3,4,5] should return [-1,2,-3,4,-5]

User FullStack
by
7.0k points

1 Answer

2 votes

Is this computer science?

If so, then the function you would need for your code is this...

_____

if (someValue%2 != 0) {

value *= -1;

}

_____

//basically number%2 == 0 means even so "!" means false so "not even" meaning "odd."

Assuming you are doing an array list (given a set value) or a for-loop with an

int someValue = Integer.parseInt(args[i]); inside (not given a set value and not restricted)

Otherwise ignore me....lol

User Larry Battle
by
6.4k points