public class b5
{
public static void main(String[] args)
{
Scanner hni = new Scanner(System.in);
System.out.print("Masukkan tinggi : ");
int n = hni.nextInt();
System.out.println("");
for(int j=1;j<=2*n+1;j++)
{
System.out.print("*");
}
System.out.println("");
for(int i=1;i<=n;i++)
{
for(int j=1 ;j<=i;j++)
System.out.print("*");
for(int k=1;k<=2*(n-i)+1;k++)
System.out.print(" ");
for(int m=1; m<=i ;m++)
System.out.print("*");
System.out.println("");
}
for(int i=1;i<n;i++)
{
for(int j=1 ;j<=n-i;j++)
System.out.print("*");
for(int k=1;k<=2*i+1;k++)
System.out.print(" ");
for(int m=1; m<=n-i ;m++)
System.out.print("*");
System.out.println("");
}
for(int j=1;j<=2*n+1;j++)
{
System.out.print("*");
}
}
}
output :
import java.util.*;
public class b4
{
public static void main(String[] args)
{
Scanner hni = new Scanner(System.in);
System.out.print("Masukkan tinggi : ");
int n = hni.nextInt();
System.out.println("");
for(int i=1;i<=n;i++)
{
for(int j=1 ;j<=n-i+1;j++)
System.out.print("*");
for(int k=1;k<=2*i-1;k++)
System.out.print(" ");
for(int m=1; m<=n-i+1 ;m++)
System.out.print("*");
System.out.println("");
}
for(int i=1;i<=n;i++)
{
for(int j=1 ;j<=i;j++)
System.out.print("*");
for(int k=1;k<=2*(n-i)+1;k++)
System.out.print(" ");
for(int m=1; m<=i ;m++)
System.out.print("*");
System.out.println("");
}
}
}
output :
public class b4
{
public static void main(String[] args)
{
Scanner hni = new Scanner(System.in);
System.out.print("Masukkan tinggi : ");
int n = hni.nextInt();
System.out.println("");
for(int i=1;i<=n;i++)
{
for(int j=1 ;j<=n-i+1;j++)
System.out.print("*");
for(int k=1;k<=2*i-1;k++)
System.out.print(" ");
for(int m=1; m<=n-i+1 ;m++)
System.out.print("*");
System.out.println("");
}
for(int i=1;i<=n;i++)
{
for(int j=1 ;j<=i;j++)
System.out.print("*");
for(int k=1;k<=2*(n-i)+1;k++)
System.out.print(" ");
for(int m=1; m<=i ;m++)
System.out.print("*");
System.out.println("");
}
}
}
output :