我正在尝试将来自扫描仪的用户输入读取为整数数组,我现在有这个:
int [] arr1 = {Integer.parseInt(sc.nextLine().split(" "))};
但是我得到了错误
String[] cannot be converted to String
Any help would be much appreciated :)
sc.nextLine().split(" ") //This returns String[]
int a = Integer.parseInt("") //Integer.parseInt requires one String param.
尝试以下代码:
String input = sc.nextLine();
String[] inputs = input.split(" ");
List<Integer> ints = Arrays.asStream(inputs).
map(Integer:parseInt).collect(Collectors.toList());
检查文件:API:Integer.parseIntString.split()