Monday , December 18 2017
Home / Blue J / java program for pattern#12

java program for pattern#12

Java program for pattern with indentation or spacing

    1
   12
  123
 1234

This is a simple java program for pattern with indentation.
Indentation in pattern is thus required. This can be done using extra for loop to provide the required indentation per line.

 class format4 
 {
 public static void main(String args[]) 
 {
 int i,j; 
 for(i=1;i<5;i++) 
 {
  	for(j=5;j>=i;j--)
 	System.out.print(' ');
 	for(j=1;j<=i;j++) // Inner For loop for printing values required in output 
	System.out.print(j); // Prining the value of j as this is what needed in output.
	System.out.println(); // New line for changing the row
 }
 }
 }

OUTPUT:

Pattern 1 12 123 1234
Java program for pattern
Also See:   C Program for Drawing a Line using Bresenham Line Algorithm

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

Leave a Reply

Your email address will not be published. Required fields are marked *