[英]error messages of int can't be converted to a boolean and bad operand for ||
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int N = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
if ( N % 2 == 1)
{
System.out.println("Weird");
}
else if ( N % 2 == 0 && N <= 20 && N >= 6 )
{
System.out.println("Weird");
}
else if ( N = 2 || 4)
{
System.out.println("Not Weird");
}
else
{
System.out.println("Not Weird");
}
scanner.close();
System.out.println(N);
}
}
错误信息Solution.java:27: error: bad operand types for binary operator '||' else if ( N = 2 || 4) ^ 第一种类型:int 第二种类型:int Solution.java:27:错误:类型不兼容:int 不能转换为布尔值 else if (N = 2 || 4) ^
您需要使用以下内容:
else if ( N == 2 || N == 4)
在这个例子中:
else if ( N = 2 || 4)
有2个问题。
n
分配给 2,而不是进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.