Skip to content

Instantly share code, notes, and snippets.

@feehe21
Created October 17, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feehe21/a5e9dead85576a0757a85460fc46e7b4 to your computer and use it in GitHub Desktop.
Save feehe21/a5e9dead85576a0757a85460fc46e7b4 to your computer and use it in GitHub Desktop.
import java.util.*;
/**
* Write a description of class syllable here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class syllable
{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("Enter a word to find out how many syllables it has");
String word = scan.nextLine();
List<Integer> vowelSpot = new ArrayList<Integer>();
for(int i = 0; i < word.length(); i++){
if(word.substring(i, i+1).equals("a") ||
word.substring(i, i+1).equals("e") ||
word.substring(i, i+1).equals("i") ||
word.substring(i, i+1).equals("o") ||
word.substring(i, i+1).equals("u")){
vowelSpot.add(i);
}
}
for(int i = 1; i < vowelSpot.size(); i++){
if(vowelSpot.get(i) == vowelSpot.get(i - 1) + 1){
vowelSpot.remove(i);
if(i < vowelSpot.size()){
if(vowelSpot.get(i) == vowelSpot.get(i - 1) + 2){
vowelSpot.remove(i);
}
}
}
}
System.out.println("Syllables: " + vowelSpot.size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment