Hacker News new | past | comments | ask | show | jobs | submit login

In Java

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?




The deadline for YC's W25 batch is 8pm PT tonight. Go for it!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: