WRITE A PROGRAM TO PRINT A BINARY RIGHT ANGLED TRIANGLE UPTO N TERMS IN JAVA

class Btri

{

public static void main(String args[])

        {

            int i, j,n;

          n=Integer.parseInt(args[0]);               

          for (i = 1; i <= n; i++)

            {

                for (j = 1; j <= i; j++)

                {

                    if (j % 2 == 0)

                    {

                        System.out.print(“0 “);

                    }

                    else

                    {

                        System.out.print(“1 “);

                    }

                }

                    System.out.println(“”);

            }

         }

      }

  • OUTPUT:
btrijava.JPG

Leave a Comment

Your email address will not be published.