java从键盘上输入5个整数存进数组a中打印输出

import java.util.InputMismatchException;

import java.util.Scanner;

 

public class ExceptionTest2 {

 

public static void main(String[] args)throws Exception {

// TODO 自动生成的方法存根

 

try{

int a[]=new int[5];

System.out.println("输入5个整数");

 

for(int i=0;i<10;i++){

 

Scanner sc=new Scanner(System.in);

a[i]=sc.nextInt();

 

}

 

for(int j=0;j<5;j++)

{

System.out.print("a["+j+"]="+a[j]+",");

}

 

}

catch(ArrayIndexOutOfBoundsException e){

//System.out.println(e.getMessage());

e.printStackTrace();

}

catch(InputMismatchException e){

//System.out.println(e.getMessage());

e.printStackTrace();

 

}

 

finally{

System.out.println("感谢使用本程序");

}

 

 

 

 

 

}

 

}