import java.util.Scanner;
public class NumAverage {
public static void main (String [] args)
{
//int a,b;
int[] numbers = new int [10];
Scanner numreader = new Scanner(System.in);
try
{
System.out.println("Enter 10 num");
for (int i = 0; i < numbers.length; i++)
numbers[i] = numreader.nextInt();
//numbers[i] = Integer.parseInt(s)
//for (int i = 0; i < numbers.length; i++)
//{
//sum += numbers[i];
//}
}
catch(NumberFormatException numfo)
{
System.out.println(numfo.getMessage() + "cannot be converted to integer");
}
}
}
如果用户尝试输入字符串而不是整数,我如何才能将我从键盘输入到数组中的数字变为 parseInt