Reputation: 71
When trying to compile i'm being given the error message: Bad operand types for binary operator '| |' first type: int; second type: int.
This is the code i have written, although it isn't finished.
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("*");
}
}
Please could you tell me what this means and how i can fix it?
Upvotes: 1
Views: 10756
Reputation: 25980
Don't be confused between =
and ==
operators :
if (row == 1 || row == squareSize)
=
is used to assignate a value to a variable, whereas the second is used to process a logical comparison between two variables.
Upvotes: 0
Reputation: 6765
Change if (row = 1 || row = squareSize)
to if (row == 1 || row == squareSize)
.
What is happening now is you are doing assignments to the variable row and then ORing the numbers together, which is wrong.
Upvotes: 0
Reputation: 13887
if (row = 1 || row = squareSize)
=
is an assignment operator, not a equality/relational operator.
I think you want ==
:
if (row == 1 || row == squareSize)
Upvotes: 3