Explanation :
If n=6 then output will be
*
**
***
****
*****
****** .
Code:
import java.util.Scanner;public class StarPattern5
{
public static void main( String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no. of lines: ");
int line=sc.nextInt();
int i,j,k,t=0,samp=1;
for (i=1; i<=line; i++)
{
for (j=line; j>=i; j--)
{
System.out.printf(" ");
}
for (k=1; k<=i; k++)
{
System.out.printf("*");
}
System.out.printf("\n");
}
}
}
No comments:
Post a Comment