IDEA debug总结

调试一次编程题,发现没有掌握debug技巧,确实费事,做一次总结,方便以后回顾。

Run to Cursor

跳到光标处,适用于快速跳过循环,定位到光标处,而不用到处打断点,使用断点跳转。非常实用的一个功能。

Rrop Frame

Debug程序的时候,是否遇到过因为“下一步”按太快,而导致跳过了想要深入分析的那段代码?是不是很想要有“回到上一步”这样的操作呢?在IDEA中就提供了一个帮助你回退代码的机会。

但是这种回退并不是万能的,比如如下的顺序结构就不能回退。

void test() {
    int a = 1;
    int b = 2;
    int c = a + b;
    System.out.println(c);
}

当你setp into 一个函数的时候,就可以看到这个 Drop Frame的图标,Rrop Frame指的是回退回上一层函数进入的那句语句。

来源:

IDEA Debug过程中如何回退操作?_idea调试回退到上一步_keep one's resolveY的博客-CSDN博客

Set Value

修改值,当你需要不断测试一个函数不同输入时候的输出是否正确,可以和Rrop Frame搭配使用,不断测试一个函数的结果

 来源:

https://www.cnblogs.com/acm-bingzi/p/debugModifyValue.html

测试代码

import java.util.Scanner;

/**
 * T
 * m n
 */
public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int t = in.nextInt();
            String[] results=new String[t];
            for (int t0 = 0; t0 < t; t++) {
                int m = in.nextInt();
                int n = in.nextInt();
                String[][] ms = new String[m][m];
                for (int j = 0; j < m; j++) {
                    for (int i = 0; i < m; i++) {
                        ms[j][i] = in.next();
                    }
                }
                String[][] ns = new String[n][n];
                for (int j = 0; j < n; j++) {
                    for (int i = 0; i < n; i++) {
                        ns[j][i] = in.next();
                    }
                }
                String result = process(m, n, ms, ns);
                results[t0]=result;
            }
            for (String result : results) {
                System.out.println(result);
            }
        }
    }

    private static String process(int m, int n, String[][] ms, String[][] ns) {
        boolean eq = true;
        int c = m - n;
        for (int i = 0; i <= c; i++) {
            for (int j1 = 0; j1 < n; j1++) {
                for (int i1 = 0; i1 < n; i1++) {
                    String n1 = ns[j1][i1];
                    String m1 = ms[j1 + i][i1 + i];
                    boolean eq1 = m1.equals(n1);
                    eq = eq && eq1;
                    if(eq){
                        continue;
                    }
                }
            }
            if(eq){
                break;
            }
        }
        if (eq) {
//            System.out.println("Yes");
            return "Yes";
        } else {
            return "No";
//            System.out.println("No");
        }
    }

}

猜你喜欢

转载自blog.csdn.net/csdncjh/article/details/131998266