⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error_2.java

📁 Java异常
💻 JAVA
字号:
//运行时的错误。(逻辑错误)
//一、引用数组边界外部的元素
/*
class Error_3{
	public static void main(String args[])
	{
		int grades[]={82,90,64,80,95,75};
		grades[6]=0;
	}
}
*/

//二、忘记在图形用户界面的应用程序中调用System.exit
/*
import javax.swing.JOptionPane;
class Error_3{
	public static void main(String args[])
	{	
	  JOptionPane.showMessageDialog(null,"I love java!");
	  System.exit(0);
	
	}
}

*/
//三、1避免程序陷入死循环
/*
class Error_2{
	public static void main(String args[])
	{
		int grades[]={82,90,64,80,95,75};
		int accumulator=0;
		int counter=6;
		double average=0;
		
		
		for(int i=0;i<grades.length;)
		{
		  System.out.println(grades[i]);
		  accumulator=accumulator+grades[i];
		}
		average=accumulator/counter;
		System.out.println();
		System.out.println("平均成绩为:"+average);
		System.exit(0);
		}
		}
		
*/
//三、2没有为while结构提供中止的途径
/*
class Error_2{
	public static void main(String args[])
	{
		int counter=2;
		System.out.println("酒店的楼梯有....");
		while (counter<21){
		System.out.println(counter);
		//counter++;
	    }
	 }
}
*/
//三、3忘记在break语句中编写必要的break语句	 
/*
class Error_2{
	public static void main(String args[])
	{
		int x=2;
		switch(x)
		{
			case  1:
				System.out.println("x is 1");
				//break;
			case  2:
				System.out.println("x is 2");
				//break;
			case  3:
				System.out.println("x is 3");
				//break; 
			default:
			    System.out.println("x is not 1,2or 3");
		}
	}
}
*/
//四、除以0
/*
class Error_2{
	public static void main(String args[])
	{
		System.out.println(4/0);
    }

}
*/


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -