Answer:
// here is code in java.
public class NAMES
{
// main method
public static void main(String[] args)
{
int n=4;
// print the upper half
for(int a=1;a<=n;a++)
{
for(int b=1;b<=n-a;b++)
{
// print the spaces
System.out.print(" ");
}
// print the * of upper half
for(int x=1;x<=a*2-1;x++)
{
// print the *
System.out.print("*");
}
// print newline
System.out.println();
}
// print the lower half
for(int y=n-1;y>0;y--)
{
for(int z=1;z<=n-y;z++)
{
// print the spaces
System.out.print(" ");
}
for(int m=1;m<=y*2-1;m++)
{
// print the *
System.out.print("*");
}
// print newline
System.out.println();
}
}
}
Explanation:
Declare a variable "n" and initialize it with 4. First print the spaces (" ") of the upper half with the help of nested for loop.Then print the "*" of the upper half with for loop. Similarly print the lower half in revers order. This will print the required shape.
Output:
*
***
*****
*******
*****
***
*