Solution in java ONLY plz... FULL question can be found on the following link http://ntci.on.ca/compsci/java/ch5/5_9.html ---> question 14
I cannot put full question here as its too long... so full question is on the link
The requirement is for it to NOT be done with import java.io.*; etc..... just directly
Thanks, appreciate it
----------------------------------------------------------------------------------
Write a program that prints portions of Pascal's triangle. The program should repeatedly ask the user to supply the number of rows in the triangle, terminating when the user supplies the value zero. In printing a triangle, the first value in the last row should appear in the first column and each preceding row should start printing three spaces further right........
class Main {
public static int fact(int i)
{
if (i == 0)
return 1;
return i * fact(i - 1);
}
public static void main(String[] args)
{
int n = 4;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print(" "+ fact(i)/ (fact(i - j)* fact(j)));
}
System.out.println();
}
}
}
Comments
Really appreciate your help!!!!!!!!!!!!!!!!
Leave a comment