数组赋值异常的问题 这里你输入错误的话就应该是指你输入的不是数字这样会报:java.util.InputMismatchException异常根本没有到数组赋值哪里,当下次循环开始时,还是读取控制台上次的输入,所有依然报错! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 已经解决经过大师指点最终版 给大家看看 是否可行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]); }} 这两行代码输出什么结果? Java程序员该如何理解“回调函数”? 如何在java程序里启动和杀死进程 自己写的一个线程的简单代码,为什么屏幕上面什么也没有?请教教我 环境变量的问题 数据库连接问题 来自java初学者的史上最菜问题,期待各位答复 java中的报表打印及套打问题 stmt.executeUpdate("insert into st(st_id,st_name)values(st_id,st_name)");??? html help workshop 问题 异常------求助啊 java 正则表达式匹配字符串
经过大师指点最终版 给大家看看 是否可行
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]);
}
}