public class Pascal
{
public static long[] getRow(int rowNum) { long[] thisRow = new long[rowNum]; if(rowNum == 1) { thisRow[0] = 1; } else { long[] lastRow = getRow(rowNum - 1); thisRow[0] = 1; thisRow[rowNum - 1] = 1; for(int i = 1; i < rowNum - 1; i++) { thisRow[i] = lastRow[i - 1] + lastRow[i]; } } return thisRow; } public static void main(String args[]) { int getRowNum = Integer.parseInt(args[0]); long[] pasc = Pascal.getRow(getRowNum); for(int i = 0; i < pasc.length; i++) { System.out.print(pasc[i] + " "); } System.out.print("\n"); }
Edit, cleaned up code:
How do I paste into here whilst preserving line breaks?
public class Pascal
{
}Edit, cleaned up code:
How do I paste into here whilst preserving line breaks?