Computer Science, asked by Sharmaseema52, 4 months ago

write a java program to print following patterns.

*
##
* * *
####
* * * * *​

Answers

Answered by tijarejanhavi
0

Explanation:

*

* *

* * *

* * * *

* * * *

Let’s write the java code to understand this pattern better.

Answered by anindyaadhikari13
1

Question:-

Write a Java program to print the following pattern.

Code:-

import java.util.*;

class Pattern

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows for the pattern: ");

int n=sc.nextInt();

char ch='#';

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

{

ch=(ch=='#')?'*':'#';

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

System.out.print(ch+" ");

System.out.println();

}

}// end of main()

}// end of class

Run:-

Enter the number of rows for the pattern: 5

*

# #

* * *

# # # #

* * * * *

Similar questions