pTutorial

New way to learn Programming

Java print star pattern using array

Following Java program print the stars per line equal to the array element per index let’s suppose an array named x having 3 element

5 6 3


Then the pattern is like that
*****
******
***

Java star pattern example

class PrintStar
{
public static void main(String ...s)
{
int x[]={5,3,5,3};
for(int i=0;i<x.length;i++)
{
int z=x[i];
for(int j=0;j<z;j++)
{
System.out.print("*");
}
System.out.println(" ");
}
}}

Output

***** 
*** 
***** 
*** 

See Also


QUOTES OF THE DAY

Knowledge without integrity is dangerous and dreadful.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER