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

Gaurav
         Please help for me how to create in a pattern of eight 🌟.And output is a 8of pattern in star
ADI
          import java.util.Scanner; public class Welcome { public static void main(String args[]) { Scanner sc= new Scanner(System.in); System.out.println("enter the rows"); int rows= sc.nextInt(); System.out.println("here is the pattern"); int i, j, k=0; String tmp1=""; String tmp2=";"; int m=rows-1; for(i=1; i<=rows; i++) { for(j=0; j<=k; j++) { tmp1 = tmp1 + "*"; } k = k + 2; System.out.println(tmp1+ j +"\n"); tmp1 = ""; } for (i=rows; i<=m;i++) { for (j=k;j<=1;j--) { tmp2 = tmp2 + "*"; } k = k - 2; System.out.println(tmp2+ j +"\n"); tmp2 = ""; } } } i have been trying to print something like this *1 ***3 *****5 *******7 *****5 ***3 *1 can you tell me where is my mistake in the program
Varsha K S
         Please help me out with 1 3*2 4*5*6 10*9*8*7

©candidjava.com