java——数字金字塔代码

来源:互联网 发布:网络存储空间 编辑:程序博客网 时间:2024/06/08 08:53
import java.util.Scanner ;public class Test2{public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("请输入1-15之间的数:");int number = input.nextInt();for(int a = 0; a<number;a++){             //第一个for循环控制循环次数(显示几行)for(int d = number-a-1;d>0;d--)System.out.print("  ");  //这里的第二个for循环是让数字居中显示for(int b = a+1;b>0;b--){        //第三个for循环从大到小System.out.print(b+" ");if(b==1){for(int c = b+1;c<a+2;c++){    //这里的循环数字从小到大System.out.print(c+" ");}}}System.out.println("");}}}
0 0
原创粉丝点击