{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

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

{[ snackBarMessage ]}