Vowels - str = str.toLowerCase(); // for consistent...

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

View Full Document Right Arrow Icon
//******************************************************************** // Vowels.java Author: Lewis and Loftus // // Solution to Programming Project 3.15 //******************************************************************** / import java.util.Scanner; i public class Vowels { //----------------------------------------------------------------- // Counts the number of each vowel in a string. //----------------------------------------------------------------- public static void main (String[] args) { int acount = 0, ecount = 0, icount = 0, ocount = 0, ucount = 0; int other = 0; System.out.println ("Enter a string of characters:"); Scanner sc = new Scanner(System.in); String str = sc.nextLine();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: str = str.toLowerCase(); // for consistent counting for (int index = 0; index < str.length(); index++) { switch (str.charAt (index)) { case 'a': acount++; break; case 'e': ecount++; break; case 'i': icount++; break; case 'o': ocount++; break; case 'u': ucount++; break; default: other++; } } System.out.println (); System.out.println ("Number of each vowel in the string:"); System.out.println ("a: " + acount); System.out.println ("e: " + ecount); System.out.println ("i: " + icount); System.out.println ("o: " + ocount); System.out.println ("u: " + ucount); System.out.println ("other characters: " + other); } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online