Created
October 17, 2018 18:34
-
-
Save feehe21/a5e9dead85576a0757a85460fc46e7b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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