Tutorials

Java Basic Programs


Java Star Pattern Program


In this chapter of java programming tutorial, our task is to write simple java program:

  • to print various star patterns

Java star pattern program 1

package BasicPrograms;

public class StarPattern1 {

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

	}

}

OUTPUT

**** 
*** 
** 

Java star pattern program 2

package BasicPrograms;

public class StarPattern2 {

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

	}

}

OUTPUT

*****
*****
*****
*****
*****

 

Java star pattern program 3

package BasicPrograms;

public class StarPattern3 {
	public static void main(String args[]){
	
		for(int i=1;i<=5;i++){
			for(int j=0;j<5-i;j++)
				System.out.print(" ");
			for(int l=1;l<=i;l++)
				System.out.print("*");
			System.out.println();
		}

	}

}

OUTPUT

    *
   **
  ***
 ****
*****

Write a simple java program to create below patterns:

1.
*****
*    *
*    *
*    *
*****  
 
2. 
*****
****
***
**
*
+
++
+++
++++
+++++ 

 



Please Share this page
Views : 43
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!