我需要更基本的方法!這將只是將單詞分成1,2,3個連續的隔間,我的「水」輸出應該是數組字符串!例如水的輸入應該產生如{「w」,「a」,「t」,「e」,「r」,「wa」,「at」,「te」,「er」,「wat」,「吃」, 「之三」}一種接收字符串輸入並將其分爲1,2和3個不同部分的方法
public void split(String word) {
int x=(word.length())/2;
int z=word.length();
String[] partition= new String[5];
for (int i=0; i<x; i++){
String new1=Character.toString(word.charAt(i));
String new2 = Character.toString(word.charAt(i))+Character.toString(word.charAt(i+1));
String new3 = Character.toString(word.charAt(i))+Character.toString(word.charAt(i+1))+Character.toString(word.charAt(i+2));
String new4 = removeDuplicate(Character.toString(word.charAt(z-2))+ Character.toString(word.charAt(z-1)));
String new5 = removeDuplicate(Character.toString(word.charAt(z-3))+ Character.toString(word.charAt(z-2))+ Character.toString(word.charAt(z-1)));
char result = word.charAt(2);
String[] partitions = {new1,new5,new3,new4,new2};
//partition=partitions;
//Arrays.toString((removeDuplicates(partitions)))
System.out.println(partitions);
}
//return partition;
}
你有沒有試過爲自己寫?這不是一個代碼寫入服務。 – 2014-10-04 21:02:15
向我們展示您無法工作的嘗試。 – MarGar 2014-10-04 21:02:56