Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Do While loop + switch, Vowel Count

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Do While loop + switch, Vowel Count

    I'm working on a program to count the number of vowels entered by the user, but so far have been getting these 2 errors:

    VowelsEnteredUntilFullStop.java:18: possible loss of precision
    found : int
    required: char
    letter = keyboardIn.nextInt();
    ^
    VowelsEnteredUntilFullStop.java:33: possible loss of precision
    found : int
    required: char
    total = total + letter;
    ^
    2 errors

    The line in bold is the error being flagged.

    // 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
    	[B]letter = keyboardIn.nextInt();[/B]
     
    	do
    	{  
    		System.out.println("Enter a letter: ");
    	}
    	while(letter != '.');
     
    	switch (total)
    	{
    	        case 'a' :
    		case 'e' :
    		case 'i' :
    		case 'o' :
    		case 'u' :
    		total = total + letter;
    		vowelCount++;
    	}
     
    	System.out.println("The number of vowels is" + vowelCount);
    	}
    }
    Last edited by mwardjava92; November 9th, 2011 at 10:15 AM. Reason: USE HIGHLIGHT TAGS!


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Do While loop + switch, Vowel Count

    You haven't posted a description of your issue and you haven't added highlight tags. Not a good start...

    I can see 2 casting errors.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: Do While loop + switch, Vowel Count

    Sorry, thats it edited now.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Do While loop + switch, Vowel Count

    Do not duplicate threads. Your other has been deleted.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. How do I loop a switch Statement?
    By Arkeshen in forum Java Theory & Questions
    Replies: 10
    Last Post: August 2nd, 2018, 07:47 AM
  2. How to Count the CAPS
    By Sean137 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 14th, 2010, 08:30 AM
  3. Method to count objects
    By mjpam in forum Java Theory & Questions
    Replies: 5
    Last Post: July 28th, 2010, 08:49 AM
  4. select count(*)
    By jacinto in forum JDBC & Databases
    Replies: 4
    Last Post: March 2nd, 2010, 10:30 PM
  5. private method , loop , switch , help?
    By wolfgar in forum Loops & Control Statements
    Replies: 9
    Last Post: November 8th, 2009, 11:04 PM