zoukankan      html  css  js  c++  java
  • 课堂作业

    1. 用户用你的程序读入一个数组文件 (就像我们以前做过的那样),显示初始状态 (就像围棋打谱程序那样)

    1.1. 用户也可以自行定义数组的大小。

    2. 用户这时候有两个选择

    2.1 按 单步执行 键, 在 GUI 看到你的程序是如何一步一步算出目前最大子数组的范围,当前计算到的临时子数组是在哪里,等等。 最好用不同的颜色标识不同的状态。

    2.2 按 自动运行 键, 在 GUI 看到程序自动运行,并自动显示过程, 每次改变状态的时候要稍作停留 (例如 1 秒钟的时间)

    3. 最好有一个 倒带 / 回滚 的键, 让用户可以看清楚关键的几步。

    package snippet;
    import java.util.*;
    public class t {
    static int n;
    static String[] demo = new String[100];//用来记录每次执行后的结果等信息
    static Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
    // TODO 自动生成的方法存根
    int st=0,end = 0;//记录子数组的开始与末尾
    int a=0;//记录执行次数
    int sum = 0;
    int value = 0; 
    System.out.println("输入数组的个数");
    n = in.nextInt();
    int num[] = new int[n];
    System.out.println("输入数组中的值");
    for(int i = 0;i < n;i++)
    {
    num[i] = in.nextInt();
    }
    sum = num[0];
    for(int i = 0;i < n;i++)
    {
    if (value <= 0) {
    value = num[i];
    st = i;
    end ++;
    a++;
    }else {
    value += num[i];
    end ++; 
    a++;
    } 
    if (sum < value) { 
    sum = value;
    demo[i] = "第" + (i+1) + "步:" +"此时的最大子数组为" + sum + "从"+ (st+1) + "到" + end + "已经计算了" + a + "个子数组" ;
    
    }else {
    demo[i] = "第" + (i+1) + "步:" +"此时的最大子数组为" + sum + "从"+ (st+1) + "到" + end +"已经计算了" + a + "个子数组";    
    } 
    }
    done();
    System.out.println("最大值为" + sum);
    }    
    public static void done()
    {
    int stop,k;
    System.out.println("是否执行但不调试,单步调试请1,");
    stop = in.nextInt();
    if (stop != 1) {
    for(int i = 0 ; i < n ; i++)
    {
    System.out.println(demo[i]);
    }
    }
    else {
    for(int i = 0 ; i < n ; i++)
    {
    System.out.println("继续执行请按1");
    stop = in.nextInt();
    if (stop == 1) {
    System.out.println(demo[i]);
    continue;
    }
    }
    }
    int choice = 0; 
    while(choice != 1)
    {
    System.out.println("是否需要回滚,回滚请按0");
    choice = in.nextInt();
    if (choice == 0) {
    System.out.println("请输入需要回滚到的步数");
    k = in.nextInt();
    System.out.println(demo[k-1]);
    }
    }
    }
    }
  • 相关阅读:
    六、springboot集成Swagger2
    五、springboot单元测试
    四、Springboot Debug调试
    三、springboot热部署
    二、springboot配置
    一、springboot入门
    SpringBoot整合RabbitMQ
    消息总线
    分布式配置
    路由网关---zuul
  • 原文地址:https://www.cnblogs.com/123456www/p/10770729.html
Copyright © 2011-2022 走看看