【发布时间】:2016-11-12 16:04:20
【问题描述】:
package myProjects;
import java.util.*;
public class Acm3 {
static int numberOfFriends;
static int rowOfChocolate;
static int columnOfChocolate;
static String division;
static Scanner myScanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("How many friends you want to distribute?");
numberOfFriends = myScanner.nextInt();
System.out.println("How do you want to distribute?");
division = myScanner.next();
String[] myArray = division.split("\\s");
int[] myArray1 = new int[numberOfFriends];
int i;
for (i = 0; i <= numberOfFriends; i++); {
myArray1[i] = Integer.parseInt(myArray[i]);
System.out.print(myArray1[i]);
}
}
}
我正在尝试将String 数组转移到Int Array。我有一个字符串数组,想将每个元素转换为int,最后转换为数组。有谁能帮忙吗?
提前致谢
【问题讨论】:
-
接下来请格式化您的代码(时间缩进 4 个空格或使用 {} 按钮)。另请注意,循环后有一个杂散分号,因此花括号中的块仅运行一次,而不是您可能期望的每个数组元素运行一次。
-
你得到什么错误?在哪一行?