Results 1 to 3 of 3
  1. #1
    JayP is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default Triangle Pattern with numbers

    Hi I'm trying to do a triangle pattern, I've done this before but I'm really lost for how to do it with incrementing numbers.

    e.g.,

    1
    12
    123
    1234
    ...

    Java Code:
    	public static void drawPattern(int n)
    	{
    		  
    
    	        // loop N times, one for each row
    	        for (int i = 0; i < n; i++) {
    
    	            // print j *
    	            for (int j = 0; j < i; j++)
    	                System.out.print("*");
    
    	            // print a new line
    	            System.out.println();
    	}

    Could someone give me a heads up on how I could change this code to make it with numbers?

    Any information would be greatly appreciated!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Change the "*" to be the number you want.
    Last edited by Norm; 06-05-2011 at 07:45 PM.

  3. #3
    JayP is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default

    Thanks, I solved it using a different method, using j as my print and changing some of the loop parameters.

Similar Threads

  1. Star triangle pattern
    By crazy4fun in forum New To Java
    Replies: 7
    Last Post: 03-06-2011, 02:03 PM
  2. strategy pattern and bridge pattern
    By jomypgeorge in forum New To Java
    Replies: 2
    Last Post: 12-13-2010, 06:13 AM
  3. Triangle using Numbers
    By Anandt88 in forum New To Java
    Replies: 16
    Last Post: 06-05-2010, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •