2016-01-02 40 views
-2
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]); 
} 

//有誰知道,因爲權不是建立我如何使這項工作,但是當我運行它,它給我如果0我需要創建一個用戶,它的工作原理給定數字數組,但一直給我0

//有人能告訴我或給我解釋一下什麼是錯的,這將有助於

+0

您創建的數組,然後從來沒有把任何東西在裏面。 – chrylis

+0

添加這個作爲循環的第一行:'intArray1 [i] = Integer.parseInt(three [i]);' – Bohemian

回答

0

的問題是,你創建的數組intArray1,你印它不會增加它的任何元素。這就是爲什麼它給出0作爲結果。 而不是創造intArray1的,以下列方式打印出數組three

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); 
     } 
    } 
} 
相關問題