Java program to print patterns of numbers and stars



Program1

package com.candidjava;

public class PyramidPattern1 
{
	public static void main(String[] args) 
	{
		int n=4;
		for(int i=0;i<n;i++)
		{
			System.out.println("\n");
			for(int j=0;j<=i;j++)
			{
				System.out.print(" * ");
			}
		}
		
	}

}

Output

 * 

 *  * 

 *  *  * 

 *  *  *  * 


Program 2

package com.candidjava;

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


Output

        * 

      * * 

    * * * 

  * * * * 

* * * * * 




Related Post

Comments


©candidjava.com