Simple Pyramid
Given below is an example of a simple type of pyramid that you can easily create using the Java code given after the example.
//By GadTool.blogspot.com
public class Simple_pyramid {
public static void main(String args[]) {
int x, y, num=10;
for(x=1;x<=num;x++){
for(y=0;y<x;y++){
//Adding an Asterisk(*) followed by a space
System.out.print("* ");
}
//Changing the line
System.out.println();
}
}
}
public class Simple_pyramid {
public static void main(String args[]) {
int x, y, num=10;
for(x=1;x<=num;x++){
for(y=0;y<x;y++){
//Adding an Asterisk(*) followed by a space
System.out.print("* ");
}
//Changing the line
System.out.println();
}
}
}
Numbered Pyramid
Given below is an example of a pyramid that you can easily create using the Java code given after the example.Here the asterisk(*) is replaced by numbers.
You are gonna understand the program in a better way seeing the below example⤵️

//By GadTool.blogspot.com
public class NumberPyramid {
public static void main(String args[]) {
int x, y, num=12, nomme=1;
for(x=1;x<=num;x++){
for(y=0;y<x;y++){
//printing the value of the variable 'nomme'
System.out.print(nomme+" ");
nomme=nomme+1;
}
System.out.println();
nomme=1;
}
}
}
public class NumberPyramid {
public static void main(String args[]) {
int x, y, num=12, nomme=1;
for(x=1;x<=num;x++){
for(y=0;y<x;y++){
//printing the value of the variable 'nomme'
System.out.print(nomme+" ");
nomme=nomme+1;
}
System.out.println();
nomme=1;
}
}
}
Triangular Pyramid
Given below is an example of a triangular pyramid that you can easily create using the Java code given after the example.Here the look of the pyramid is altered.
You are gonna understand the program in a better way seeing the below example⤵️

//By GadTool.blogspot.com
public class Triangular_pyramid {
public static void main(String args[]) {
int x, y, num=10, j, nu=num/2, xe=0;
for(x=1;x<=nu;x++){
for(j=nu-xe;j>1;j--){
System.out.print(" ");
}
for(y=0;y<x;y++){
//Adding an Asterisk(*) followed by a space
System.out.print("* ");
}
System.out.println();
xe=xe+1;
}
}
}
public class Triangular_pyramid {
public static void main(String args[]) {
int x, y, num=10, j, nu=num/2, xe=0;
for(x=1;x<=nu;x++){
for(j=nu-xe;j>1;j--){
System.out.print(" ");
}
for(y=0;y<x;y++){
//Adding an Asterisk(*) followed by a space
System.out.print("* ");
}
System.out.println();
xe=xe+1;
}
}
}
Pine Tree
Given below is an example of a pine tree created by using the pyramids discussed above.You are gonna understand the program in a better way seeing the below example⤵️

//By GadTool.blogspot.com
public class pine_tree {
public static void main(String args[]) {
int x, y, num=10, j, nu=num/2, xe=0;
//Creating a tringular pyramid
for(x=1;x<=nu;x++){
for(j=nu-xe;j>1;j--){
System.out.print(" ");
}
System.out.print(" ");
for(y=0;y<x;y++){
System.out.print("* ");
}
System.out.println();
xe=xe+1;
}
int co;
//Creating loop to create two similar types of triangular pyramids
for(co=0;co<=1;co++){
xe=0;
for(x=3;x<=nu;x++){
for(j=nu-xe;j>1;j--){
System.out.print(" ");
}
for(y=0;y<x;y++){
System.out.print("* ");
}
System.out.println();
xe=xe+1;
}
}
//Creating the bark
for(x=3;x<=nu;x++){
System.out.print(" ");
for(y=0;y<3;y++){
System.out.print("*");
}
System.out.println();
}
}
}
public class pine_tree {
public static void main(String args[]) {
int x, y, num=10, j, nu=num/2, xe=0;
//Creating a tringular pyramid
for(x=1;x<=nu;x++){
for(j=nu-xe;j>1;j--){
System.out.print(" ");
}
System.out.print(" ");
for(y=0;y<x;y++){
System.out.print("* ");
}
System.out.println();
xe=xe+1;
}
int co;
//Creating loop to create two similar types of triangular pyramids
for(co=0;co<=1;co++){
xe=0;
for(x=3;x<=nu;x++){
for(j=nu-xe;j>1;j--){
System.out.print(" ");
}
for(y=0;y<x;y++){
System.out.print("* ");
}
System.out.println();
xe=xe+1;
}
}
//Creating the bark
for(x=3;x<=nu;x++){
System.out.print(" ");
for(y=0;y<3;y++){
System.out.print("*");
}
System.out.println();
}
}
}
0 Comments