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 5 of 5

Thread: Looping through an Array.

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Looping through an Array.

    Hello, i need some help. I need to loop through an array to determine if there are vowels, consonants, a space etc. and then print for example. "character [x] located at position [x] is a consonant" or "character [x] located at position [x] is a vowel" etc. I have a small idea but cannot figure it out.

     String ArrayMyName[] = {"Hector & Jorge % Farinas"};
            int ArrayLenght = ArrayMyName.length;
            for(int counter =0; counter < ArrayLenght; counter++)
             {
                String vowel = "a,e,i,o,u";
                if(ArrayMyName[counter].equals(vowel))
                System.out.println("Character" + ArrayMyName[counter] + "located in position " + ArrayMyName[counter] + "is a vowel.");
     
             }
     
             }

    Thank you so much in advance..
    Last edited by kl2eativ; June 10th, 2011 at 06:36 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,776
    Thanks
    54
    Thanked 2,340 Times in 2,311 Posts

    Default Re: Looping through an Array.

    Look at the methods of the String class such as indexOf(). The equals() method isn't the one to use here.
    you need to have two loops: one to look at each name and within that loop, another loop to check the current name to see if it contains one of the letters you are interested in.

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Looping through an Array.

    Where can I find the complete list of the String methods?

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Looping through an Array.

    Is seems as though your loop compares each string in ArrayMyName to the entire string vowel. I would recommend comparing each character in the string to the character(s) you are going to want to find. Hope this helps.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,776
    Thanks
    54
    Thanked 2,340 Times in 2,311 Posts

    Default Re: Looping through an Array.

    The API doc address: Java Platform SE 6

    Scroll down in the lower left for the String class.

Similar Threads

  1. Help in looping
    By endframe in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 28th, 2010, 03:24 PM
  2. Looping with an ArrayList
    By EmSaint in forum Loops & Control Statements
    Replies: 3
    Last Post: September 23rd, 2010, 01:06 AM
  3. Looping through Tokens
    By Viking N7 in forum Loops & Control Statements
    Replies: 2
    Last Post: September 12th, 2010, 01:06 PM
  4. Looping through a multidimensional array
    By MysticDeath in forum Loops & Control Statements
    Replies: 2
    Last Post: October 11th, 2009, 06:41 PM
  5. [SOLVED] looping, for,while,do-while.
    By chronoz13 in forum Loops & Control Statements
    Replies: 4
    Last Post: August 6th, 2009, 02:32 PM