Java program to print pyramid triangle with star and numbers


Program 1

package com.candidjava.star;

public class Star10
{

	public static void main(String args[])
	{
		int i, j, k;
		for (i = 1; i <= 5; i++)
		{
			for (j = i; j < 5; j++)
			{
				System.out.print(" ");
			}
			for (k = 1; k < (i * 2); k++)
			{
				System.out.print("*");
			}
			System.out.println("");
		}
		for (i = 4; i >= 1; i--)
		{
			for (j = 5; j > i; j--)
			{
				System.out.print(" ");
			}
			for (k = 1; k < (i * 2); k++)
			{
				System.out.print("*");
			}
			System.out.println("");
		}
	}
}

Output 1

    *

   ***

  *****

 *******

*********

 *******

  *****

   ***

    *


Program 2

package com.candidjava.star;

public class Star11
{

	public static void main(String[] x)
	{
		int i, j, k;
		for (i = 1; i <= 4; i++)
		{
			for (j = 1; j <= i; j++)
			{
				System.out.print("*");
			}
			for (k = 4; k >= j; k--)
			{
				System.out.print("e");
			}
			System.out.println();
		}
	}

}

Output 2

*eee

**ee

***e

****






Related Post

Comments

Arnab
          1 4*9 16***25

©candidjava.com