Write a java program to print following pattern
*********
*******
****
**
*
Answers
Sample input is given
import java.io.*;
// Java code to demonstrate star patterns
public class anyname
{
// 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=n; i>=0; i--)
{
// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=i; j>=0; j--)
{
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 9;
printStars(n);
}
}
Given pattern:
* * * * *
* * * *
* * *
* *
*
Program in Java to print the given pattern:
class Pattern
{
public static void main (string args [])
{
for( int i=5; i>=5; i--)
{
for (int j=1; j<=i;j++)
{
System.out.print ("*");
}
System.out.println ();
}
}
}