Program for Full Pyramid and size can be input by user.
import java.util.*;
public class Pyramid
{
public static void main(String Args[])
{
int n;
Scanner sc = new Scanner(System.in);
n= sc.nextInt();
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < (n - i); j++)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print(" * ");
for (int k = 1; k < i; k++)
System.out.print(" * ");
System.out.println();
}
for (int i = n - 1; i >= 1; i--)
{
for (int j = 0; j < (n - i); j++)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print(" * ");
for (int k = 1; k < i; k++)
System.out.print(" * ");
System.out.println();
}
System.out.println();
}
}
import java.util.*;
public class Pyramid
{
public static void main(String Args[])
{
int n;
Scanner sc = new Scanner(System.in);
n= sc.nextInt();
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < (n - i); j++)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print(" * ");
for (int k = 1; k < i; k++)
System.out.print(" * ");
System.out.println();
}
for (int i = n - 1; i >= 1; i--)
{
for (int j = 0; j < (n - i); j++)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print(" * ");
for (int k = 1; k < i; k++)
System.out.print(" * ");
System.out.println();
}
System.out.println();
}
}
No comments:
Post a Comment