Star printing program in Java: pattern 7
Code for this pattern:
import java.util.Scanner;
public class star {
public static void main(String[] args) {
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=1;j<=6-i;j++)
{
System.out.print("*");
}
for(k=1;k<i;k++)
{
System.out.print(" ");
}
for(j=1;j<=6-i;j++)
{
System.out.print("*");
}
System.out.print("\n");
}
for(i=2;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
for(k=1;k<=5-i;k++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.print("\n");
}
}
}
Try this in C.
Post a Comment