zoukankan      html  css  js  c++  java
  • YanghuiTriangle

    Demand

    1 用实现循环队列
    2 参考PPT用循环队列打印杨辉三角
    3 用JDB或IDEA单步跟踪排队情况,画出队列变化图,包含自己的学号信息
    4 把代码推送到代码托管平台
    5 把完成过程写一篇博客:重点是单步跟踪过程和遇到的问题及解决过程
    6 提交博客链接

    Codes

    package AfterclassTest;
    
    import java.util.Scanner;
    
    /**
     * Created by jxy6996 on 2017/10/17.
     */
    public class YangHui {
    
            public static void main(String[] args)
            {
                System.out.println("请输入杨辉三角的行数");
                Scanner in=new Scanner(System.in);
                int a=in.nextInt();
                int arr[][]=new int[a][a+2];
                for (int i=1;i<=a ; i++)
                {
                    arr[i-1][0]=0;
                    arr[i-1][i+1]=0;
                }
                if (a==1)
                {
                    System.out.println(" 1 ");
                }
                if (a==2)
                {
                    System.out.println("   1 ");
                    System.out.println(" 1 2 1");
                }
                else
                {
                    arr[0][1]=1;
                    for (int j=2;j<=a ;j++ )
                    {
                        for (int k=1;k<=j ;k++ )
                        {
                            arr[j-1][k]=arr[j-2][k-1]+arr[j-2][k];
                        }
                    }
                    for (int i=1;i<=a ;i++ )
                    {
                        for (int space=0;space<=a-i ;space++ )
                        {
                            System.out.print(" ");
                        }
                        for (int j=1;j<=i ;j++ )
                        {
                            System.out.print(arr[i-1][j]+" ");
                        }
                        System.out.println();
                    }
                }
            }
        }
    
    

    Debug

    队列变化图

    Error

    • 第三步开始就没法往下执行,百度后没能查找到解决方案……需要请老师帮忙

    • 请教王老师后发现debug没法往下执行是因为没有在console里输入行数,导致一直在运行,输入后即可

  • 相关阅读:
    面向对象-01
    网络编程-02-客户端搭建
    网络编程-01-服务端搭建
    日志-02
    日志-01
    md5加密
    shell 第五天
    shell第四天
    shell第三天
    shell
  • 原文地址:https://www.cnblogs.com/JXY6996/p/7680122.html
Copyright © 2011-2022 走看看