Recent Tutorials and Articles
    More pattern printing in java
    Published on: 29th July 2013

    Another java program to print the numbered triangular pattern

    Pattern to print
    
             1
            234
           56789
          0123456
         789012345
        67890123456
       7890123456789
      012345678901234
     56789012345678901
    2345678901234567890
    
    
    Pattern2.java
    public class Pattern2 {
    
    	public static void main(String[] args) {
    		int rows = 10;
    		int valueToPrint = 0;
    
    		for (int i = 0; i < rows; i++) {
    
    			for (int j = 0; j < rows - i - 1; j++) {
    				System.out.print(" ");
    			}
    
    			for (int k = 1; k <= (2 * i) + 1; k++) {
    				System.out.print((++valueToPrint) % 10);
    			}
    
    			System.out.println();
    		}
    
    	}
    
    }
    
    
    Output
    
             1
            234
           56789
          0123456
         789012345
        67890123456
       7890123456789
      012345678901234
     56789012345678901
    2345678901234567890
    
    

    You can easily change the size of pattern by increasing/decreasing the value of rows variable.

    Thank you for reading through the tutorial. In case of any feedback/questions/concerns, you can communicate same to us through your comments and we shall get back to you as soon as possible.

    Published on: 29th July 2013

    Comment Form is loading comments...