链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
题目描述
输出双层金字塔。
输入描述:
多个测试数据。每个测试数据输入一个整数n( 2 <= n <= 9)
输出描述:
输出双层金字塔
示例1
输入
2 5
输出
*
***
*
*
***
*****
*******
*********
*******
*****
***
*
代码:
import java.util.Scanner;
//牛客知识点学习22204:上下金字塔
public class Test25 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
while (scanner.hasNextInt()){
int n=scanner.nextInt();
x(n);
}
}
public static void x(int n){
for (int i = 1; i <=n; i++) {
for (int j = n-i; j >=1 ; j--) {
System.out.print(" ");
}
for (int j = 1; j <=2*i-1 ; j++) {
System.out.print("*");
}
System.out.println();
}
for(int i = n-1;i >= 1;i--){
for (int j = n-i; j >=1 ; j--) {
System.out.print(" ");
}
for(int j = 1;j <= 2 * i - 1;j++){
System.out.print("*");
}
System.out.println();
}
}
}
![在Ubuntu-22.04 [WSL2]中配置Docker](https://i-blog.csdnimg.cn/direct/44a03d15d8874e629fae4ec4a1d2d7a0.png)


















