在尝试编译时,我收到了错误消息:二元运算符'|的操作数类型错误|”第一种类型:int;第二种类型:int .
这是我写的代码,虽然还没有完成 .
public class Main
{
public static void main ( String [] args )
{
int squareSize = BIO.getInt();
for(int row = 0; row == squareSize; row++)
{
if (row = 1 || row = squareSize)
{ for(int stars = 0; stars <=squareSize; stars++)
System.out.print("*");
}
}
请问您能告诉我这意味着什么以及如何解决这个问题?
4 回答
=
是赋值运算符,而不是相等/关系运算符 .我想你想
==
:将
if (row = 1 || row = squareSize)
更改为if (row == 1 || row == squareSize)
.现在发生的事情是你正在对变量行进行赋值,然后将数字进行OR运算,这是错误的 .
不要在
=
和==
运算符之间混淆:=
用于为变量赋值,而第二个用于处理两个变量之间的逻辑比较 .需要使用== not =