Computer Science, asked by shardul1925, 1 year ago

The question is in the attachment.Write the program in JAVA language.


Hoping for correct program.


Please do not write if you do not know.




Attachments:

Answers

Answered by dhanya25077
0

check it :

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++)  

           {  

               // 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);  

   }  

}  

Output:

*  

* *  

* * *  

* * * *  

* * * * *

After 180 degree rotation

filter_none

edit

play_arrow

brightness_4

import java.io.*;  

 

// Java code to demonstrate star pattern  

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 spaces  

           // values changing acc. to requirement  

           for(j=2*(n-i); j>=0; j--)  

           {  

               // printing spaces  

               System.out.print(" ");  

           }  

             

           //  inner loop to handle number of columns  

           //  values changing acc. to outer loop  

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

           {  

               // 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);  

   }  

}  

Output:

       *

     * *  

   * * *  

 * * * *  

* * * * *

hope it helps u..


shardul1925: this porgram does not work dear
shardul1925: program*
dhanya25077: it will work see this link if u r confused...
shardul1925: bro i want that particular pattern to print
Answered by siddhartharao77
7

Sample Program to print pattern in Java:

import java.util.*;

class Brainly

{

public static void main(String args[])

{

int i,j,k,n;

Scanner demo = new Scanner(System.in);

System.out.println("Enter the number of rows: ");

n = demo.nextInt();

System.out.println("\n");

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

{

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

{

System.out.print("  ");

}

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

{

System.out.print("*");

}

System.out.println();

}

for(i = n - 1; i >= 1; i--)

{

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

{

System.out.print(" ");

}

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

{

System.out.print("*");

}

System.out.println();

}

}

}

Hope it helps!  -------- Good Luck!

Attachments:

shardul1925: Thank You Sir.
siddhartharao77: Most welcome :-)
Topperworm: Superb answer dear
siddhartharao77: Thank you so much dear
Similar questions