hi guys.iv been trying hard to do a code which requires me to separate a word into syllables in java but i dont no hw to do it.
the word:someone

in syllable: so/me/on/e

Recommended Answers

All 10 Replies

But the word someone only has two syllables not four. Do you mean something else than syllables?

I wrote this a while ago because I wanted to implement the Fletch readability index.

The question really has nothing to do with Java (but of course you can express the method in Java). The basic idea is that every group of vowels marks a new syllable. Then you can make this simple rule more precise by adding exceptions (not Java exceptions, English exceptions).

Given a word, just iterate though the letters with a for loop and the String charAt method. Write a boolean isVowel method to make the syllable count easier and more readable. You can also use the String split method to beak up the string into an array of strings at the vowel grouping marks.

am just a java dummy.yes someone has two syllables i made a mistake.can you please implement those methods needed for me please.

Nobody here will write those mthods for you. This isn't a "we do your homework" service.
If you would like to learn how to write them yourself then lots of people here will help you learn. Post what you have done so far.

First come up with an algorithm, and I seriously doubt you're going to do that.
In fact I seriously doubt there exists an algorithm that can do it, and even worse if you have to do it for several languages.
Most likely you're going to end up having to do some sort of dictionary lookup and maintain a dictionary you have to build manually.

import java.util.Scanner;

public class Syllable

import java.util.Scanner;

public class Syllable
  public static void main(String[]args)
  String txt = "someone";
  System.out.println("txt="+txt+" countSyllables="+countSyllables(txt));  
  System.out.println("INPUT A WORD");

  Scanner input = new Scanner(System.in);
  String str = input.nextLine(); 

  String val = "Lesego";
  String[] parts = str.split("\\^");
   * this only count syllables
   * */
 public static int countSyllables(String word)
   //The letter 'y' can be counted as a vowel, only if it
   //creates the sound of a vowel (a, e, i, o, u).
    char[] vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
    char[] currentWord = word.toCharArray();
    int numVowels = 0;
    boolean lastWasVowel = false;
    for (char wc : currentWord) {
        boolean foundVowel = false;
        for (char v : vowels)
            //don't count diphthongs
            if ((v == wc) && lastWasVowel)
                foundVowel = true;
                lastWasVowel = true;
            else if (v == wc && !lastWasVowel)
                foundVowel = true;
                lastWasVowel = true;
        // If full cycle and no vowel found, set lastWasVowel to false;
        if (!foundVowel)
            lastWasVowel = false;
    // Remove es, it's _usually? silent
    if (word.length() > 2 && 
            word.substring(word.length() - 2) == "es")
    // remove silent e
    else if (word.length() > 1 &&
            word.substring(word.length() - 1) == "e")
    return numVowels;


OK, that's not complete, but it's certainly heading in the right direction, and almost there. If you need help to proceed, please say exactly what help you need.

i really want to learn how to split but not to count syllables

were are not here to do your homeworks! DiY do it yourself! LOL

commented: Dishonest (wants the same himself), rude -3

then why do you post your own thread with exactly the same question?

Be a part of the DaniWeb community

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