Answer to Question #271225 in Java | JSP | JSF for ilveprogram

Question #271225

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

Thanks, appreciate it

I cannot put full question here as its too long... so full question is on the link

----------------------------------------------------------------------------------


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........


1
Expert's answer
2021-11-25T00:53:15-0500
import java.io.*;
class GFG {
	public int factorial(int i)
	{
		if (i == 0)
			return 1;
		return i * factorial(i - 1);
	}
	public static void main(String[] args)
	{
		int n = 4, i, j;
		GFG g = new GFG();
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= n - i; j++) {
				System.out.print(" ");
			}
			for (j = 0; j <= i; j++) {
				System.out.print(
					" "
					+ g.factorial(i)
						/ (g.factorial(i - j)
							* g.factorial(j)));
			}
			System.out.println();
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS