2012-04-03 100 views
2

嗨我正在嘗試編寫一個程序,用羅馬尼亞語的規則將單詞分隔成多個音節。試圖做到這一點比我想的要困難得多,因爲我不知道如何創建這個規則。我到目前爲止所知道的情況並且我知道在這種情況下代碼不正確,但我需要檢查汽車陣列中的字母是否存在於vocale數組中,然後檢查汽車數組中的下一個字母是否存在於consoane數組中一個在這裏是我所知道的,如果條件輸入錯了,我只是需要一個解決方案,以檢查條件的代碼:將單詞分解爲音節

String[] vocale = {"a", "e", "i", "o", "u"}; 
String[] consoane = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"}; 
public String DesparteCuvant(String cuv){   
    String[] car = new String[cuv.length()]; 
    String c = ""; 

    for(int i = 0; i < cuv.length(); i++){ 
     car[i] = cuv.substring(i, i+1); 

    } 


    for (int j = 0; j < car.length - 2; j++){ 
     if(car[j] == vocale[] && car[j+1] == consoane[] && car[j+2] == vocale[]){ 

     } 

    }    

    return c; 
} 
+0

什麼是羅馬尼亞規則替換?我在哪裏可以找到一個定義?很想實施那個。 – santa 2012-04-03 09:09:31

+0

你可以在這裏找到rulles alto他們在羅馬尼亞語中使用谷歌瀏覽器來翻譯網頁我無法在英語中輸入rulles對不起 – user1146440 2012-04-03 09:26:56

+0

http://www.scritube.com/literatura-romana/gramatica/DESPARTIREA-CUVINTELOR-IN -SILA1622024117.php – user1146440 2012-04-03 09:27:08

回答

1

好吧,如果你只是想獲得的if語句的工作,這是我應該怎樣做:

private final Set<String> vocale = new HashSet<String>(); 
private final Set<String> consoane = new HashSet<String>(); 

private init(){ 
    // fill the sets with your strings 
} 

private boolean isVocale(String s){ 
    return vocale.contains(s); 
} 

private boolean isConsoane(String s){ 
    return consoane.contains(s); 
} 

和你的if語句應該是這樣的:

​​
1

我想你可以使用regular expressions這項任務。他們讓你更容易寫下這樣的模式。

作爲例子

// following is the enough to specify a "complex" pattern 
Pattern rule1 = Pattern.compile("([aeiou][bcdfghjklmnpqrstvwxyz][aeiou])"); 

Matcher matcher= rule1.matcher(strLine); 
while (matcher.find()){ 
    String aMatch= matcher.group(1); 
    // do what you need to do 
} 

將是您的

for (int j = 0; j < car.length - 2; j++){ 
    if(car[j] == vocale[] && car[j+1] == consoane[] && car[j+2] == vocale[]){ 
    } 

}