Java 我需要用用户给定的数字创建一个数组,它可以工作,但一直给我0 System.out.println(“请输入多项式项的系数:”); 字符串系数=keyboard.nextLine(); 字符串[]三=coefficents.split(“”); int[]intArray1=新的int[3.长度]; for(int i=0;i

Java 我需要用用户给定的数字创建一个数组,它可以工作,但一直给我0 System.out.println(“请输入多项式项的系数:”); 字符串系数=keyboard.nextLine(); 字符串[]三=coefficents.split(“”); int[]intArray1=新的int[3.长度]; for(int i=0;i,java,arrays,compiler-errors,Java,Arrays,Compiler Errors,//有人知道我如何使它工作吗?因为它不是构建的,但当我运行它时,它会给我0 //如果有人能告诉我或向我解释什么地方出了问题,这会有所帮助,问题是你在数组1中创建了数组,并且你在打印时没有添加任何元素。这就是为什么它的结果是0。 不要在数组1中创建intArray1,而是按以下方式打印数组3: System.out.println("Please enter a coefficients of a polynomial’s terms:"); String coefficents = ke

//有人知道我如何使它工作吗?因为它不是构建的,但当我运行它时,它会给我0


//如果有人能告诉我或向我解释什么地方出了问题,这会有所帮助,问题是你在数组1中创建了数组,并且你在打印时没有添加任何元素。这就是为什么它的结果是
0
。 不要在数组1中创建
intArray1
,而是按以下方式打印数组
3

System.out.println("Please enter a coefficients of a polynomial’s terms:");
    String coefficents = keyboard.nextLine();
    String[] three = coefficents.split(" ");
    int[] intArray1 = new int[three.length];

for (int i = 0; i < intArray1.length; i++) {
 System.out.print(intArray1[i]);
}

您创建了数组,但从未在其中放入任何内容。将其添加为循环的第一行:
intArray1[i]=Integer.parseInt(三[i])
import java.util.Scanner;

public class test {
    public static void main(String args[]){
        Scanner user_input = new Scanner(System.in);
        System.out.println("Please enter the coefficients of a polynomial’s terms:");
        String coefficents = user_input.nextLine();
        String[] three = coefficents.split(" ");
        for (String i: three) {
            System.out.print(i);
        }
    }
}