Results 1 to 3 of 3
  1. #1
    herpeslurpy is offline Member
    Join Date
    Nov 2012
    Rep Power

    Question Just a little help with some code?

    I have an assignment in my class where I need to make a program that prompts you for input, then finds the consonants and vowels and displays the number of each. the best I could come up with is to find one of either the consonants and vowels, and subtract that from the total number of letters to find the other. I've thought of using each vowel as a char. array to keep it simple, but I'm having trouble incorporating the array into the math, along with accounting for spaces and punctuation.
    here's my code so far:

    import java.util.*;
    public class VowCons {
    public static void main(String[] args) {
    String input = "";

    char[] vowelArray = {'a','e','i','o','u'};

    Scanner words = new Scanner(;
    System.out.println("Enter a string:");

    int characters = input.length();
    int vowels=0;
    int consonants=characters - vowels;

    System.out.println("There are " +vowels+ " vowels");
    System.out.println("There are " +consonants+ " consonants");


    The main thing I'm having trouble with is the value of the vowels variable (mouthful, right?) to have something to properly subtract from. Thanks in advance.
    Edit- I forgot to put it in, but I've been using if statements, but to no avail.
    Last edited by herpeslurpy; 12-08-2012 at 09:10 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Just a little help with some code?

    You need to loop through the char's of the String with a for loop, checking each char to see if it's a vowel or not. Please give that a go and let us know what you come up with.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Just a little help with some code?

    Please go through the Forum Rules, particularly the third paragraph.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2012, 03:40 AM
  2. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  3. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  4. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts