Inverse boolean flags

Report a typo

Write a body and a parameter of the method inverseFlags. The method must take an array of booleans and negate each of them. Do not make a copy of the parameter, change the elements of a passed array.

Sample Input 1:

true false true

Sample Output 1:

false true false
Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;

public class Main {

public static void inverseFlags(/* write a parameter here */) {
// write your code here
}

/* Do not change code below */
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
final List<Boolean> booleans = Arrays
.stream(scanner.nextLine().split("\\s+"))
.map(Boolean::parseBoolean)
.collect(Collectors.toList());
final boolean[] flags = new boolean[booleans.size()];
for (int i = 0; i < flags.length; i++) {
flags[i] = booleans.get(i);
}
inverseFlags(flags);
final String representation = Arrays.toString(flags)
.replace("[", "")
.replace("]", "")
.replace(",", "");
System.out.println(representation);
}
}
___

Create a free account to access the full topic