# Array Troubles

• October 13th, 2009, 01:21 AM
Leeds_Champion
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
• October 13th, 2009, 02:21 AM
Json
Re: Array Troubles
A simple array of characters.

Code :

``` 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
• October 13th, 2009, 11:26 PM
Leeds_Champion
Re: Array Troubles
:confused:

um, I'm not sure lol...

this is what I have so far

Code :

```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?
• October 14th, 2009, 12:04 AM
helloworld922
Re: Array Troubles
You can create an array of arbitrary length. Note that once it's created, you can't change it's length :P

Code :

`char[] someArray = new char[length];// length is how many char's can fit in this array`
• October 21st, 2009, 11:45 PM
Leeds_Champion
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 :/
• October 22nd, 2009, 12:16 AM
helloworld922
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.
• October 22nd, 2009, 11:05 AM
Leeds_Champion
Re: Array Troubles
thanks helloworld! Thats exactly what I needed :D