📄 5.java
字号:
import java.io.*;
class MyException1 extends Exception
{
public MyException1(String msg)
{ super(msg); }
}
public class ExceptionDemo2
{ public static void main(String[] args)
{int a,b;
int[] myArray = new int[3];
try
{
System.out.println("请输入数据到数组中:");
for (int i=0; i<=myArray.length; i++)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
myArray[i]=Integer.parseInt(br.readLine());
System.out.println("myArray数组的第" + i + "个元素的值是:" + myArray[i]);
}
}
catch (ArrayIndexOutOfBoundsException e)
{ System.out.println("数组下标越界。");
}
catch(IOException e)
{
}
try{
System.out.println("请输入a");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
a=Integer.parseInt(br.readLine());
if (a<0||a>100)
throw new MyException1("参数a不要1到100之间。");
}
catch (MyException1 e)
{
System.out.println(e.getMessage());
}
catch(IOException e)
{
}
try{
System.out.println("请输入b");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
b=Integer.parseInt(br.readLine());
}
catch (NumberFormatException e)
{
System.out.println("b不是整形数据。");
}
catch(IOException e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -