java编程杨辉三角
时间: 2023-12-02 17:42:58 浏览: 118
基于java实现杨辉三角
以下是Java编程实现杨辉三角的例子:
```java
public class YangHuiTriangle {
public static void main(String[] args) {
int[][] triangle = new int[10][];
for (int i = 0; i < triangle.length; i++) {
triangle[i] = new int[i + 1];
for (int j = 0; j < triangle[i].; j++) {
if (j == 0 || j == triangle[i].length - 1) {
triangle[i][j] = 1;
} else {
triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
}
System.out.print(triangle[i][j] + " ");
}
System.out.println();
}
}
}
```
阅读全文