一、测试代码
测试代码 1:
package day06;
/*
* 如何调试程序
* 1.System.out.println();
* 2.Eclipse - Debug调试
* */
public class DebugTest {
public static void main(String[] args) {
int i = 10;
int j = 20;
System.out.println("i = " + i + ", j = " + j);
int max = getMax(i, j);
System.out.println("max = " + max);
}
private static int getMax(int k, int m) {
int max = 0;
if (k < m) {
max = k;
} else {
max = m;
}
return max;
}
}
测试代码 2:
package day06;
public class DebugTest1 {
public static void main(String[] args) {
int[] arr = new int[]{1,2,3,4,5};
System.out.println(arr);//地址值
char[] arr1 = new char[]{'a','b','c'};
System.out.println(arr1);//abc
}
}
二、如何调
1. 设置断点
注意:可以设置多个断点
2. debug as java application
3. 常用操作

本文介绍了两种Java程序调试方法:使用System.out.println()打印变量状态和利用Eclipse的Debug模式进行逐步跟踪。通过两个示例代码展示了如何设置断点并执行debug as Java application,帮助读者掌握基本的Java调试技能。
161

被折叠的 条评论
为什么被折叠?



