Computer Science, asked by avanimore287, 2 months ago

Write a java program to generate the following patterns using iteration(loop) statements :
*
* #
* # *
* # * #
* # * # *

Answers

Answered by amrapalidas1967
1

Answer:

public class Patt

{

public static void main(String args[])

{

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

{

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

{

if(j%2==0)

{

System.out.print("#");

}

else

System.out.print("*");

}

System.out.println();

}

}

}

Explanation:

Decoding the pattern

It is the same as:-

1

12

123

1234

12345

just replace the odd numbers with "*"

and even numbers with "#"

Similar questions