guys please help! im having trouble splitting a word into syllables. what i have so far is splitting a word into different compartment bt cant do syllables, i want the code to to be able slice a part of a word,by looking, vowels INSIDE the word!at the end of each vowel, it should slice e.g given word "code" OUTPUT should be "co" ,"de". if itsa setswana word like "motho"(which means a person), i should get output like "mo" and "tho"
this is what i have so far

public void splitter(String word)
{

ArrayList<String> list = new ArrayList<String>();
for (int i = 1; i <= 3; i++) {
int limit = word.length() - i + 1;
for (int j = 0; j < limit; j++) {
list.add(word.substring(j, j+i));
}
}
System.out.println(list);
}

Recommended Answers

All 11 Replies

Before you go too far with that solution I feel I should point out that splitting after a vowel won't always give you correct syllables. For example, you used CODE, saying the result should be "co" and "de" but code is a monosyllable word.
As is TOW, DAWN, RACE and a lot of other words that won't fit your algorithm. Splitting accurately by syllable is a lot more complicated than splitting after a vowel.

i understand with english! bt my example was only in reference with my native language as is the project im am trying to code! im doing a program that can separate syllables in SETSWANA LANGUAGE! and in setswana its very much like that

Then I stand corrected (and learnt something).
One solution would be to build up an array of the vowels and then progress through the word checking each letter. If it exists in the vowel array you split at that point and continue going until you hit the end.

yes you are correct! i can identify vowels bt which method do i use to split?

Use String's split method with a regex that specifies one or more vowels.

why is he creating a new account for every post...

Do you have any evidence to indicate that Vinolia and sekwamote are the same person?

i tried to do using split method bt! doesnt work for words like "kamoso" which should be "ka" "mo" "so" bt its different

 public void syllable(String word)
   {
    int i=0;
     int z=0;
   for (i=i;i<word.length()-1; i++){
    char w = word.charAt(i);
     String w1=Character.toString(w);
   if(w=='a'|| w=='e' || w=='i' || w=='o' || w=='u')
    {
       String[] x= word.split(w1,2);

    System.out.println(Arrays.toString(x));
     //z=i;
     continue;
     }  
     continue;
     }
 }

i managed to do it thanks for contribution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.