LAB C - out .println( "Pleace enter a number...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class pascalTriangle { public static long [] pascal ( int numberOfLines, int top, long [] someArray) { if (top <= numberOfLines) { long num = factorial (top) * factorial (numberOfLines - top); someArray[top] = factorial (numberOfLines) / (num); pascal (numberOfLines, top + 1, someArray); } else return someArray; return someArray; } public static long factorial ( int num) { if (num == 0) return 1; else return (num * factorial (num - 1)); } } import java.util.Scanner; public class PascalTest extends pascalTriangle { public static void main(String[] args) { Scanner scan = new Scanner (System. in ); System. out .println( "******* BEGINING OF THE TEST *******" ); while ( true ){ System. out .println(); System.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: out .println( &quot;Pleace enter a number from 1 (top of triangle) to 16&quot; ); System. out .print( &quot;15 to show the Nth line of Pascal's&quot; + &quot;Triangle (enter -1 or 0 to exit): &quot; ); int num = scan.nextInt(); long someA = new long [num]; System. out .println(); if (num == -1 || num == 0) { System. out .print( &quot;***** END OF THE TEST *****&quot; ); break ; } else if (num &gt; 16) { System. out .println( &quot;Only number from 1 to 16 are efficient&quot; ); continue ; } int top = 0; pascal (num - 1, top, someA); for ( int i = 0; i &lt; someA. length ; i++){ System. out .print(someA[i] + &quot; &quot; ); } } } }...
View Full Document

This note was uploaded on 01/23/2012 for the course CS 111C taught by Professor Metzler during the Spring '11 term at City College of San Francisco.

Page1 / 2

LAB C - out .println( &amp;amp;quot;Pleace enter a number...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online