InterviewSolution
| 1. |
Write a Java program to print Pascal’s Triangle Pattern. |
|
Answer» public class Main { public static void printPascalsTriangle(int n){ for (int i = 0; i < n; i++) { int number = 1; System.out.printf("%" + (n - i) * 2 + "s", ""); for (int j = 0; j <= i; j++) { System.out.printf("%4d", number); number = number * (i - j) / (j + 1); } System.out.println(); } } public static void main(String[] args) { int n = 8; printPascalsTriangle(n); }} Output: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1ConclusionDesign Patterns ensure that the reusable solutions that are well-tested are implemented which improves the code flexibility and paves way for DEVELOPING smart and EXTENDIBLE solutions that solve problems easily. Due to this, the demand for software developers to KNOW the best design practices and implementation has been rising steadily. These are generally discussed in the LLD (Low-Level Design) round of the company interviews. In this article, we have covered the most commonly asked design patterns interview QUESTIONS for both freshers and experienced software professionals. Useful Resources:
|
|