Vowels - return (1 + countVowels(S.substring(1))) } return...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import java.util.Scanner public class Vowels { static public int countVowels(String S){ // if string is non-empty proceed with self calls, otherwise return 0 // to clear recursive calls on the stack if(!S.isEmpty()){ if(S.charAt(0) == 'a' || S.charAt(0) == 'e' || S.charAt(0) == 'i' || S.charAt(0) == 'o' || S.charAt(0) == 'u' /*|| S.charAt(0) == 'A' || S.charAt(0) == 'E' || S.charAt(0) == 'O' || S.charAt(0) == 'U'*/){ /*All this control structure does is checks for a lowercase or uppercase * it is a recursive call adds 1 if it is a vowel 0 if not and calls itself*/
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return (1 + countVowels(S.substring(1))) } return (0 +countVowels(S.substring(1))) } return 0 } public static void main(String args) { Scanner keyboard = new Scanner(System.in) System.out.println( "Enter a string and I will tell you how many vowels there are" ) String input = keyboard.next() input = input.toLowerCase() System.out.println("There are " + countVowels(input) + " vowels (a/e/i/o/u) in the string you gave") S } }...
View Full Document

This note was uploaded on 09/16/2009 for the course CS 3345 taught by Professor Ozbirn during the Spring '08 term at University of Texas at Dallas, Richardson.

Ask a homework question - tutors are online