Eclipse开启断言(Assert)

1.Run -> Run Configurations -> Arguments -> VM arguments文本框中加上断言开启的标志:-enableassertions 或者-ea

2.在myEclipse中,Windows -> Preferences ->Java ->Installed JREs ->点击正使用的JDK ->Edit ->Default VM Arguments文本框中输入:-ea

例子:

public class Lmt03 {

	public static void main(String[] args) {
		int [] score = { -120,98,89,120,99};
		int sum = 0;
		for (int number : score) {
			assert number>=0:"负数不能是成绩。";
			sum = sum+number;
		}
		System.out.println("总成绩:"+sum);
	}
}



猜你喜欢

转载自blog.csdn.net/Coloured_Glaze/article/details/52078833
今日推荐