Computer Science, asked by Anonymous, 10 months ago

write a java program to generate the following pattern:

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

Answers

Answered by devc5622
1

Answer:

import java.io.*;  

 

// Java code to demonstrate star patterns  

public class GeeksForGeeks  

{  

   // Function to demonstrate printing pattern  

   public static void printStars(int n)  

   {  

       int i, j;  

 

       // outer loop to handle number of rows  

       //  n in this case  

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

       {  

 

           //  inner loop to handle number of columns  

           //  values changing acc. to outer loop      

           for(j=0; j<=i; j+2)  

           {  

               // printing stars  

               System.out.print("* ");  

           }  

//for #

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

           {  

               // printing stars  

               System.out.print("# ");  

           }    

           // ending line after each row  

           System.out.println();  

       }  

  }  

 

   // Driver Function  

   public static void main(String args[])  

   {  

       int n = 5;  

       printStars(n);  

   }  

}

Answered by GINIJno1
0

YOUR ANSWER

MARK AS BRAINLIEST ANSWER

Attachments:
Similar questions