473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

vowels in a string

14
Hi
i need help with writing a method that takes in a string of characters and counts the syllables in the string.
the method should not count chacter 'e' if its the last character in the string and by definition a syllable is vowel or a pair of adjacent vowels(a,e,o,i,u),the adjacent vowels count as one.

so my problem is identifying that the two adjacent characters are vowels.how can i tackle this?

thank you.
Feb 27 '08 #1
4 2746
chaarmann
785 Expert 512MB
Hi
i need help with writing a method that takes in a string of characters and counts the syllables in the string.
the method should not count chacter 'e' if its the last character in the string and by definition a syllable is vowel or a pair of adjacent vowels(a,e,o,i,u),the adjacent vowels count as one.

so my problem is identifying that the two adjacent characters are vowels.how can i tackle this?

thank you.
You make a function isVovel(char c) which returns true or false.
then you call this function in a loop to test if string.charAt(i) and string.charAt(i + 1) are both vowels.
Feb 27 '08 #2
Doegon
14
sorry for not giving you guys enough info,i'm trying to write a method/function so i don't know if one can write a method in another method,is there any class api that has the function of isVowel that chaarmann described may be it will be beter to call the method. thanks for the idea though
Feb 27 '08 #3
chaarmann
785 Expert 512MB
sorry for not giving you guys enough info,i'm trying to write a method/function so i don't know if one can write a method in another method,is there any class api that has the function of isVowel that chaarmann described may be it will be beter to call the method. thanks for the idea though
You cannot write a method inside a method. Just write it "in parallel" inside the same class.
There is no class in the standard API that tells you if a character is a vowel. But you can test your self with an if-statement easily
Expand|Select|Wrap|Line Numbers
  1. if (char =='a' || char =='e' || ...) return true;
or
Expand|Select|Wrap|Line Numbers
  1. if ("aeiou".indexOf(char) != -1) return true; 
or you could use a regular expression:
Expand|Select|Wrap|Line Numbers
  1. return String.valueOf(c).matches("[aeiou]");
There are may ways to do it.
Feb 27 '08 #4
Doegon
14
You cannot write a method inside a method. Just write it "in parallel" inside the same class.
There is no class in the standard API that tells you if a character is a vowel. But you can test your self with an if-statement easily
Expand|Select|Wrap|Line Numbers
  1. if (char =='a' || char =='e' || ...) return true;
or
Expand|Select|Wrap|Line Numbers
  1. if ("aeiou".indexOf(char) != -1) return true; 
or you could use a regular expression:
Expand|Select|Wrap|Line Numbers
  1. return String.valueOf(c).matches("[aeiou]");
There are may ways to do it.

Thanks man i will try and see the results, i think i get exactly what you mean.keep it real
Feb 27 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
1
by: DeFault | last post by:
I have an assigment that deals with strings and I just need an idea how to start writing these functions. Write a function that determines if a string is nice. A string is nice if it has an...
5
by: ivalki | last post by:
Hi How do i use the functions found in string.h to check if a letter is vowel and a consonant ? I have this code : ......... const char vowel="aeiou"; const char...
1
by: iloveyousosomuch | last post by:
how do i erase extra white spaces and vowels in c without using string or arrays? I just have to use char... how do i do that?
14
by: teriwalker | last post by:
import java.util.*; import java.lang.Character.*; public class IsVowel { static char vowels = { 'a', 'e', 'i', 'o', 'u', 'y' }; public static boolean isVowel(char s) {
1
by: powerej | last post by:
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use...
12
by: ashpats | last post by:
Hey everyone, I am supposed to write a program that counts the number of vowels in string of characters. It must include "Struct counter_t (it must be declared as in the code i've written)" and...
2
by: Geneses | last post by:
Hi! I'm using Eclipse as an IDE, I need to code a program where users enter a string and it computes the count for each vowel, and how many words are in the string. Users can do as many strings as...
6
by: HypeBeast McStreetwear | last post by:
Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u) For my test run I have to use "unquestionably", but I can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.