bool isVowel(char c)
{
if ((c 'u'))
return true;
else
return false ;
}
/** * Prints all characters in str that are consonants. */ public static void printConsonants(final String str) { System.out.println("Consonants in '" + str + "'"); for (final char ch : str.toCharArray()) { // Remember that a consonant is any character that is not a vowel. if (!isVowel(ch)) { System.out.println(ch); } } } /** * Prints all characters in str that are consonants, dismissing duplicates. */ public static void printUniqueConsonants(final String str) { System.out.println("Consonants in '" + str + "'"); // Store consonants in a Set to avoid printing duplicates. final Set<Character> charSet = new TreeSet<Character>(); for (final char ch : str.toCharArray()) { // Remember that a consonant is any character that is not a vowel. if (!isVowel(ch)) { charSet.add(ch); } } System.out.println(charSet); } /** * Returns true if ch is a vowel. */ public static boolean isVowel(final char ch) { return ch 'u'; }
in semi-pseudo code: get character //convert uppercase letter to lowercase letter if( 65 <= (int) character <= 90) character ^ 32 //check that a letter was given if( 97 <= (int) character <= 122) { switch(character) { case a: case e: case i: case o: case u: output "vowel" break; case y: output "consonant and/or vowel" break; default: output "consonant" break; } } else output "not a letter"
<html> <head> <title>Assignment1</title> </head> <body> Enter the String:<br><br> <form action="ass1.php" method="post"> Name: <input type="text" name="fname" /> <input type="submit" name="Submit" /> </form> <?php if(isset($_POST['Submit'])) { $vowels=array("a","e","i","o","u"); $length=strlen($_POST['fname']); $count = 0; for ($i = 0; $i!= $length; $i++) { if (array_search($_POST['fname'][$i], $vowels)) { $count++; } } } echo 'There are ('.$count.') vowels in the string ('. $_POST['fname'].')'; ?> </body> </html>
Here's the method to implement: public static boolean isVowel(char c) { String s = "" + c, a = "a", e = "e", i = "i", o = "o", u = "u"; if(s.equalsIgnoreCase(a)) return true; if(s.equalsIgnoreCase(e)) return true; if(s.equalsIgnoreCase(i)) return true; if(s.equalsIgnoreCase(o)) return true; if(s.equalsIgnoreCase(u)) return true; return false; } It returns true if the letter is a vowel, and false if it isn't. Writing code in a text box doesn't guarantee it'll work, but I'm fairly sure it will, haha.
#include <stdio.h> #include <stdlib.h> #include <string.h> main (int argc,char **argv) { char *a,*b,c; int t,e; if (argc<2) return(0); a=argv[1]; b=a; e=strlen(b); for (t=0;t<=e;t++) { c = *b; if (c>='A'&&c<='Z') c -= 'A'-'a'; if (c=='a'c=='e'c=='i'c=='o'c=='u') b++; else *a++ = *b++; } printf ("%s\n",argv[1]); return(0); }