这里你输入错误的话就应该是指你输入的不是数字
这样会报:java.util.InputMismatchException异常
根本没有到数组赋值哪里,当下次循环开始时,还是读取控制台上次的输入,所有依然报错!

解决方案 »

  1.   

    已经解决
    经过大师指点最终版  给大家看看  是否可行
    import java.util.*;
    public class Importable_1
    {
    public static void main(String[] args)
    {
    Scanner sc = new Scanner(System.in);
    int[] A = new int[3];
    int index=0;
    while(true)
    {
    try 
    {
    System.out.printf("请输入A[%d]\n", index);
    A[index] = sc.nextInt();
    index++;
    if(index>=3)
    {
    break;
    }
        }
    catch (Exception e) 
    {
    sc.next();
    System.out.printf("输入不合法,请重新输入!\n");
    }
    }
    for(int i = 0;i<A.length;i++)
    System.out.printf("A[%d] = %d\n",i,A[i]);
    }
    }