Computer Science, asked by 392raj, 1 year ago

Write a Java program to print the given pattern

Attachments:

Answers

Answered by neelbhatkar3
2

public class patternbrainly

{

public static void main(String args[])

{

int i,f;

for(i=0;i<4;i++)

{

System.out.println();

for(f=0;f<7;f++)

if(i%2==0)

{

if(f%2==0)

System.out.print("1");

else

System.out.print("0");

}

else

{

if(f%2==0)

System.out.print("0");

else

System.out.print("1");

}

}

}

}


neelbhatkar3: if you do not understand the logic tell me I will explain it to you. hope it helps you :)
neelbhatkar3: ok the first for loop is for the no of rows and the second for loop is for number of columns
neelbhatkar3: the count for no of rows and column starts from one
neelbhatkar3: sorry not from one from 0
neelbhatkar3: in the second loop it checks the positionof every element in every row whether it is at an even position or not.
neelbhatkar3: give some more time of a day and I will write the explaination in the answer itself.i will edit the answer till tom.
Similar questions