Java 在带有&;的if语句中使用char数组和boolean数组&;操作人员

Java 在带有&;的if语句中使用char数组和boolean数组&;操作人员,java,arrays,operators,Java,Arrays,Operators,我试图将布尔和字符数组与&&运算符结合使用,但收到一条错误消息,指出字符和布尔值不能与&&一起使用 任何提示都将不胜感激 private static boolean[] mergeAllCorrectPositions(boolean[] allPositions, char[] wordArray, char x) { boolean[] currentPositions = new boolean[wordArray.length]; for(int i = 0 ; i &

我试图将布尔和字符数组与&&运算符结合使用,但收到一条错误消息,指出字符和布尔值不能与&&一起使用

任何提示都将不胜感激

private static boolean[] mergeAllCorrectPositions(boolean[] allPositions, char[] wordArray, char x) {
    boolean[] currentPositions = new boolean[wordArray.length];
    for(int i = 0 ; i < wordArray.length ; i++){
        if(wordArray[i] = x && allPositions[i] = false){
            // stuff
        }
    }
    return currentPositions;
}
private static boolean[]mergeAllCorrectPositions(boolean[]allPositions,char[]wordArray,char x){
boolean[]currentPositions=new boolean[wordArray.length];
for(int i=0;i
您使用了赋值运算符而不是比较运算符

改变

if(wordArray[i] = x && allPositions[i] = false)


=是赋值运算符。要比较原语的值,需要使用==运算符。 此时,您不是在比较这些值,而是在设置它们

if(wordArray[i] = x && allPositions[i] = false){
应该是

if(wordArray[i] == x && allPositions[i] == false){
if(wordArray[i] = x && allPositions[i] = false){
if(wordArray[i] == x && allPositions[i] == false){