Computer Science, asked by sonisingh968141, 2 months ago

Pattern :-
java programming
#
# *
# * #
#*#*
# * # * #

Answers

Answered by anindyaadhikari13
2

Answer:

The given co‎de is written in Java.

public class Pattern    {

   public static void main(String args[])  {

       for(int i=1;i<=5;i++)   {

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

               if(j%2==1)

                   System.out.print("# ");

               else

                   System.out.print("* ");

           }

           System.out.println();

       }

   }

}

See the attachment for verification.

•••♪

Attachments:
Answered by kamalrajatjoshi94
2

Answer:

Program:-

public class Pattern

{

public static void main(String args[ ])

{

int i,j;

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

{

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

{

if(j%2==0)

System.out.print("*");

else

System.out.print("#");

}

System.out.println();

}

}

}

  • The logic is simple just use the loop for this pattern

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

  • Now place the condition if j is even it prints '*' else '#'

Attachments:
Similar questions