Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default The java Strings

    Good evening everyone, i would like to ask what type of String that can use in this program?

    Create a program that will receive a string from user and count the number of vowels in the string.
    i have try to use this s.indexOf() but can't
    can anyone teach me thanks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, please choose the correct sub-forum when you posting gain. This is not the correct place. I'll move your question to the correct place this time.

    What you have to do is, take each character of the string and check it for a vowel or not.

  3. #3
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    but how the code write?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You should do it. This is a forum, not a code bank. No one wants to do your homework. First show your effort, and if you have any question please ask it more clearly. We all can help you.

  5. #5
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    i didn't understand what you reply in the second post. so i just asking like that. i have let you know my way is using s.indexOf() but i still can't get it. erm, is ok..

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    What Eranga is telling you is that you have to show us why it it's working for you. What have you tried? Let's see your code.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    oh. erm.. icic sorry Eranga. this is my code.
    hope you all can help me

    import java.io.*;
    class countvowel
    {
    static DataInputStream s=new DataInputStream(System.in);
    public static void main(String args [])throws IOException
    {
    String anyvowel;
    System.out.println("Enter a string: ");
    anyvowel=s.readLine();
    System.out.println("String: "+anyvowel);
    System.out.println();
    int c = 0 ;
    for (int b = 0 ; b < anyvowel.length() ; b++) {
    if (anyvowel.charAt(b) == 'a' || anyvowel.charAt(b) == 'e'||anyvowel.charAt(b)=='i'||anyvowel.charAt(b)== 'o'||anyvowel.charAt(b)=='u') {
    c++;
    System.out.println("The vowel that have in the string:"+ anyvowel.charAt(b));
    }
    }
    System.out.println("The total number of vowel in the String: "+c);
    }
    }

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Try this in the if logic.

    Java Code:
    if(......)
    {
          c++;
          System.out.println("Vowel " + anyvowel.charAt(b) + " found at " + b);
    }


  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Subtracting Strings
    By ravian in forum New To Java
    Replies: 7
    Last Post: 10-08-2009, 06:26 PM
  2. Sorting strings in java?
    By alexander.s in forum New To Java
    Replies: 10
    Last Post: 09-01-2008, 04:14 AM
  3. Comparison of Strings
    By Cero.Uno in forum New To Java
    Replies: 3
    Last Post: 02-11-2008, 02:46 AM
  4. Comparing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:44 AM
  5. reversing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-11-2007, 08:24 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
  •