Results 1 to 7 of 7
  1. #1
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default Pascals Triangle

    Guys can anyone help get me started somehow on going about how to write this. DESIGN AND IMPLEMENT A RECURSIVE METHOD TO DISPLAY THE NTH LINE OF PASCALS TRIANGLE. the only thing i can think is that i need an array to store each line..

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Work it out on paper. Pick a number (like 5 or 6), and draw every line of Pascal's Triangle up to that point. Then think about how you determined each line in your head. Think about the criteria you use to determine which numbers would go in which order.

  3. #3
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Or to help out those who do not know post a description of what Pascal's Triangles are...so we can help you programmatically (is that a word :D)

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    Or to help out those who do not know post a description of what Pascal's Triangles are...so we can help you programmatically (is that a word :D)
    Silly guy--never took math!? =) Clicky.

    The numbers are based on binomial theorem; it is formulated as such, and procedurally generated by adding adjacent numbers for the row below.

  5. #5
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    Hey guys thanks for the responses i've been away so i couldnt reply..UGGHH.. ok so i've wrote a little bit of code but im basically shooting in the dark ..heres what i have so far..Code has some english in it so please dont critique TOO MUCH , im trying.
    Java Code:
     public class Pascal {
     	public static void main(String[] args) {  
    	
    	
    	Pascal p=new Pascal();
            int row=10;
            for(int x=0;x<=row;x++){
                for(int y=0;y<=x;y++){
                 
                    System.out.print(p.pascal(x, y)+" ");
    					 System.out.println();
    
                }
    				}
    				}
    		int pascal(int x,int y) {
          if(x=1 || x=y || y=0){
    
          }
          else{
                return pascal(x-1,y-1)+pascal(x-1,y);
    
          }
    }
    }
    //int x=row;
    //int y=col;
    i will start over if suggested if this code is completly bogus, i know its a mathematical pattern but im having trouble with all the loops and dont no if i should just use an array..i need to code this and understand it before my final pretty sure its going to be on there..using recursion...THANKS MATES

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Suppose you have the values for n-1, say, 1, 3, 3, 1. For the values for row n all you have to do is add all (left) consecutive values from the right: 1, 4, 6, 4 and add another value 1 to the right: 1, 4, 6, 4, 1. For n == 0 you have the value 1 and you don't need to know more.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by Zack View Post
    Silly guy--never took math!? =) Clicky.

    The numbers are based on binomial theorem; it is formulated as such, and procedurally generated by adding adjacent numbers for the row below.
    Boy if I got serious about math I'd be half decent :D thanks for the links

Similar Threads

  1. triangle
    By Shyamz1 in forum New To Java
    Replies: 4
    Last Post: 11-07-2010, 07:12 PM
  2. Triangle using Numbers
    By Anandt88 in forum New To Java
    Replies: 16
    Last Post: 06-05-2010, 05:10 PM
  3. ASCII Triangle
    By physics in forum New To Java
    Replies: 2
    Last Post: 03-13-2010, 02:00 AM
  4. Pascals triangle through recursion
    By hedonist in forum New To Java
    Replies: 3
    Last Post: 08-03-2009, 08:45 PM
  5. Triangle
    By jkswebsite in forum New To Java
    Replies: 8
    Last Post: 01-10-2009, 03:08 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
  •