Sandboxx:如何将一串int整数转换为一个整数数组?
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.System.*;
import static java.util.Arrays.*;
public class Sandboxx
{
public static void main(String args[])
{
Construct ion = new Construct(3, "3, 2, 1, 0");
}
}
构建:
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.System.*;
import static java.util.Arrays.*;
public class Construct
{
int length;
String s;
public Construct() {
}
public Construct(int _length) {
}
public Construct(String _s) {
}
public Construct(int _length, String _s) {
length = _length;
s = _s;
Scanner chopper = new Scanner(s);
int[] nums = new int[3];
while (chopper.hasNextInt()) {
nums = chopper.nextInt();
}
}
}
我试图把整数的字符串,(S)成整数(NUMS)阵列。我写了这段代码,但是我得到这个错误:Error:/Users/bobgalt/Construct.java:41:'.class'expected。我是java的新手,你可以看到,但我似乎无法弄清楚如何将int整个字符串放入一个int数组中。谢谢