zoukankan      html  css  js  c++  java
  • 队列加分项

    队列加分项

    作业要求

    实现代码

    public class yhsj {
        public static void main(String[] args) {
            Scanner sca = new Scanner(System.in);
            CircularArrayQueue<Integer> y = new CircularArrayQueue<Integer>();
            y.enqueue(0);
            y.enqueue(1);
            System.out.println("输入你想要的行数:");
            int count = sca.nextInt();
            for (int i = 0;i<=count;){
                int a = y.dequeue();
                int b = y.first();
                if(a==0){
                    i++;
                    y.enqueue(0);
                }
                y.enqueue(a+b);
                if (a==0)
                    System.out.println();
                else
                    System.out.print(a+"  ");
            }
        }
    }
    

    成果截图

    单步跟踪

    遇到的问题

    1. 当要求的行数过大时会打印出负数
    • 问题详情:测试中我把行数设置的较大,然后就会出现打印出负数的情况
    • 解决过程:在请教同学后,我们初步断定是数据溢出,然后我又查了一下Intege类型的最大值极限Integer.MAX_VALUE = 2147483647,这样便证实了我们的想法。
  • 相关阅读:
    java线程
    windows Server 安装
    nginx正则反向代理
    crontab定时任务启动脚本失败
    数据结构
    异常概念
    shell日期遍历复制文件
    多态和抽象
    图1 列出连通集
    PTA 代码注意事项
  • 原文地址:https://www.cnblogs.com/zhanghaolin/p/7712558.html
Copyright © 2011-2022 走看看