im trying to create a program that does as the below question asked.
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.
An example run of your program should look something like this: -
How many vowels would you like to read in? 30
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: a
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: a
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: e
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: e
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: i
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: a
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: e
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: i
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: o
Please enter a vowel (a,e,i,o,u) (30 max), # to quit: #
there are 3 a's in the array, the first appearing in index 0.
there are 3 e's in the array, the first appearing in index 2.
there are 2 i's in the array, the first appearing in index 4.
there are 1 o's in the array, the first appearing in index 8.
there are no u's in the array!
below is a small part of the code i did. im trying to first match the input and vowels and print out the result as shown in the example but i dont know what is wrong with it.
import B102. *;
public class prac
{
static int inputnum()
{
int maxnum;
System.out.println("how many vowel would you like to read in?");
maxnum=Keybd.in.readInt();
return maxnum;
}
static void inputletter(char maxletter[], int maxnum)
{
int num;
for(num=0;num<maxnum;num++)
{
System.out.println("please enter a vowel (a,e,i,o,u)" + "(" + maxnum + " max) # to quit");
maxletter[num]=Keybd.in.readChar();
}
}
static void sort(char maxletter[])
{
int num;
int count=0;
char vowels[]={'a', 'e', 'i', 'o', 'u'};
for(num=0;num<vowels.length;num++)
if(vowels[num]==maxletter[])
count++;
System.out.print(vowels[num] + count );
}
public static void main(
String args[])
{
int num;
int maxnum=inputnum();
char maxletter[]=new char[maxnum];
for(num=0;num<maxletter.length;num++)
inputletter(maxletter, maxnum);
sort(maxletter);
}
}