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.
Arrays as parameters
Inverse boolean flags
Report a typo
Sample Input 1:
true false trueSample Output 1:
false true falseWrite 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);
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.