So, I was trying to print this pattern:
1
11
101
1001
10001
Here, if the column is 1 we'll print 1 and if the row number is equal to column number then too, we'll print 1, otherwise 0. It works if I directly do it this way:
for(int i=1; i <= 6; i++)
{
for(int j=1; j<=i; j++)
{
if(j==1||j==i)
System.out.print("1");
else
System.out.print("0");
}
System.out.println("");
}
But doesn't work if I use boolean for j(the column), this way:
for(int i=1; i<=6; j++)
{
for(int j=1; j<=i; j++)
{
if(j==1)
m=true;
else
m=false;
if(m=true||j==i)
System.out.print("1");
else
System.out.print("0");
}
System.out.println("");
}
Can someone tell me why it doesn't work with boolean?
Aucun commentaire:
Enregistrer un commentaire