Anonymous user
Pascal's triangle: Difference between revisions
→{{header|Java}}
Line 336:
===Summing from Previous Rows===
{{works with|Java|1.5+}}
<java>import java.util.
...//class definition, etc.
public static void genPyrN(int rows){
if(rows < 0) return;
//save the last row here
for(int i= 0;i <= rows;++i){▼
System.out.println(last);
//work on the next row
thisRow.add(1); //beginning
//sum from the last row
▲ thisRow.add(1);
}
thisRow.add(1); //end
last= thisRow;//save this row
System.out.println(thisRow);
|