数字5个

来源:互联网 发布:云计算培训有前途吗 编辑:程序博客网 时间:2024/05/21 10:10
package fiveint;import java.util.InputMismatchException;import java.util.Scanner;public class Five{public static void main(String[] args) {System.out.println("请输入5个整数,输入0结束:");int a[]=new int[5];Scanner put=new Scanner(System.in);try {int n;for(int i=0;(n=put.nextInt())!=0;i++) {a[i]=n;}}catch(InputMismatchException e) {System.out.println("输入有误,请输入整数。");}catch(ArrayIndexOutOfBoundsException e){System.out.println("输入有误,请输入5个整数。");}finally {System.out.println("谢谢使用本程序!");}}}