exceptiondemo2.java

来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 37 行

JAVA
37
字号
/**Another simple exception example
2004.10.29. xhcprince
*/
class exceptionDemo2
{
	public static void main(String args[])
	{
		try
		{
			String s="hi";
			int a = s.length();
			int b = 42/a;

			System.out.println(a);
			try
			{
				if(a == 1)
				{
					a = a/(a-1);
				}
				if(a == 2)
				{
					int c[] = {1,3};
					c[2] = 55;
				}
			}
			catch(IndexOutOfBoundsException e)
			{
				System.out.println(e);
			}
		}
		catch(ArithmeticException e)
		{
			System.out.println(e);
		}
	}
}

⌨️ 快捷键说明

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