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

Thread: Array Troubles

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array Troubles

    ok, I have to write a code for this question

    Create a program that reads a list of vowels (a, e, i, o, u) and stores them in an array. The maximum number of vowels to be read should be obtained from the user before beginning to read the vowels, however, the user may cancel the reading of vowels at any time by entering '#'. The algorithm should then count and display the number of times each vowel appears in the array. Finally the algorithm should also output the index in the array where each vowel first appeared or a suitable message if a particular vowel is not in the array at all.

    I don't even know what an array is! We went from learning C Programming straight into Java Programming and now this is the first question that was given.

    I've looked at the tutorials on this site but not sure which array I would use for this problem. Can anyone point me in the right direction?

    Thanks


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Array Troubles

    A simple array of characters.

        char[] charArray = new char[5];
        charArray[0] = 'a';
        charArray[1] = 'e';
        charArray[2] = 'i';
        charArray[3] = 'o';
        charArray[4] = 'u';

    This is a character array which will hold a maximum of 5 items. The array index is zero based and therefore the first item can be set/get by calling charArray[0].

    Is that of any help to you?

    // Json

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Troubles



    um, I'm not sure lol...

    this is what I have so far

    import B102.*;
     
    class vowels
    {
    	public static void main(String args[])
    	{
     
    	char[] charArray = new char[5];
    	charArray[0] = 'a';
    	charArray[1] = 'e';
    	charArray[2] = 'i';
    	charArray[3] = 'o';
    	charArray[4] = 'u';
     
    	Screen.out.print("How many vowels would you like to read in?");

    then would I perform some kind of calculation?
    Last edited by helloworld922; October 14th, 2009 at 12:02 AM.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Array Troubles

    You can create an array of arbitrary length. Note that once it's created, you can't change it's length

    char[] someArray = new char[length];// length is how many char's can fit in this array

  5. #5
    Junior Member
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Troubles

    I'm still at a loss with Arrays, I have no idea how to even start writing this program, it doesn't even seem possible :/

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Array Troubles

    Have you taken a look at this yet? It's a little hard to understand at first, but it has the basics of using arrays.

  7. #7
    Junior Member
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Troubles

    thanks helloworld! Thats exactly what I needed

Similar Threads

  1. Storing an array into an array
    By vluong in forum Collections and Generics
    Replies: 4
    Last Post: September 22nd, 2009, 02:14 PM