2015-10-10 39 views
-1
public class SecretPhrase 
{ 
    public static void main(String args[]) 
    {  
     Scanner input = new Scanner(System.in);  
     String phrase= "Go Team"; //replace phrase with asterisks  
     phrase=phrase.replace("**","****"); 
     System.out.println(phrase);  
    } 
} 

爲什麼phrase不被任何東西取代?我希望整個字符串充滿*爲什麼它不能取代?

+4

因爲沒有一個*出現在你的輸入。 –

+0

@AvinashRaj,當然不是;我顯然需要休息一下。謝謝。 –

+0

@AlexShesterov :-) –

回答

0

替換功能的文檔:

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab". 
Parameters: 
target The sequence of char values to be replaced 
replacement The replacement sequence of char values 
Returns: 
The resulting string 
相關問題