在我的程序中,用戶聲明一串數字,我試圖找出數組變成數組。
實施例:將聲明的字符串轉換爲數組
WeeklyFiber week2 =新WeeklyFiber( 「CS4567」, 「13年11月24日」,32 「27,26,28 」);
我試圖找出如何將該字符串添加到我的類實例變量。
這是我有:
private String sampleID;
private String weekOfTest;
private int engineerID;
private String[] strengths = new String[20];
private static int count;
public WeeklyFiber(String sampleID, String weekOfTest, int engineerID, String strengths)
{
this.sampleID = sampleID;
this.weekOfTest = weekOfTest;
this.engineerID = engineerID;
this.strengths = strengths;
count++;
}
我的編譯錯誤消息指出不兼容的類型,需要:的String [],發現:字符串
您正試圖在構造函數中將字符串賦值給String [],這就是爲什麼編譯器會給這個 – Deepak