2013-03-30 20 views
0

我真的需要幫助修復此行我的代碼,我不斷收到這兩個錯誤:Java遞歸生成錯誤:需要數組,但找到字符串?

第一個錯誤:要求數組,但字符串發現 如果(x.length()== 0 & & y.length( )> 0 & & y [0] ==「*」)

第二個錯誤:找不到合適的方法替換(int,int)String newY = y.replace(0,1); 任何幫助,將不勝感激

//Second string is empty and there is wildCard character 
if(y.length() == 0 && wildCard) 
{ 
    return true; 
} 
if(x.length() == 0 && y.length() > 0 && y[0] == "*") 
{ 
    String newY = y.replace(0,1); 
    return match(x, newY, true); 
} 
+0

'newY'是一個'String',而你的'match'方法需要一個數組。 –

回答

3

y [0]用於數組;改用y.charAt(0)代替字符串。此外,將其與''(該字符)進行比較,而不是與另一個字符串「」進行比較。

+0

非常感謝,但我如何在Java中執行此操作String newY = y.remove(0,1); <-----這似乎不工作在Java中的任何幫助? \t { \t \t String newY = y.replace(0,1); \t \t return match(x,newY,true); \t} – mvitagames

+0

所以我假設你的意思是替換:String newY = y.replace(0,1)將不起作用,因爲0和1是int。嘗試用chars替換('0','1')。 –

+0

想要刪除0-1之間的字符串y – mvitagames

3

if(x.length() == 0 && y.length() > 0 && y[0] == "*") 

"*"是一個字符串,而不是一個字符。

此外,y[0]不適用於Java中的字符串,僅適用於數組。這可能是你的問題。

相關問題