5.java

来自「里面有我的JAVA实验和一些教程」· Java 代码 · 共 65 行

JAVA
65
字号
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 + =
减小字号Ctrl + -
显示快捷键?