|
-
November 9th, 2011, 09:07 PM
#1
Vowel Count - Do While + Switch Statement
Error:
VowelsEnteredUntilFullStop.java:33: possible loss of precision
found : int
required: char
total = total + letter;
^
1 error
// Practical 8 - Q6
// Marcus Ward
// 07/11/2011
/* Program will allow user to repeatedly enter letters.Using a do-while loop and switch
statement, the program will count the number of vowels entered until a full stop is entered. */
import java.util.Scanner;
public class VowelsEnteredUntilFullStop
{
public static void main(String[] args)
{
Scanner keyboardIn = new Scanner(System.in);
char letter = 1, vowel, vowelCount =0, total =0; // declare variables
System.out.println("Enter a letter: "); // get user input
letter = keyboardIn.next().charAt(0);
do
{
System.out.println("Enter a letter: ");
}
while(letter != '.');
switch (total)
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
total = vowelCount+ letter;
vowelCount++;
}
System.out.println("The number of vowels is" + vowelCount);
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|