I am trying to solve one of the following interview problem :
- Declare an array/list consisting of 26 alpha values, one for each letter of the alphabet.
- Iteratively scan the list for vowels, removing each vowel from this first list and putting it on a second list.
- Concatenate all elements of each list into two scalar variables (one for vowels and one for consonants), while also adding a comma between consecutive elements.
- Print the values of the two variables on the screen.
I did the first part as follows:
public static void main(String args[]){
List<String> strings = new ArrayList<String>();
Collections.addAll(strings,"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
for (String str : strings)
System.out.println(str);
}
I think I may not have understood the problem properly, the second point is talking about two lists where as in the first part, it only talks about creating one list of alphabets. Please let me know if I haven't understood something from the problem? Does combining values into two scalar variables as mentioned in third point makes sense?
Aucun commentaire:
Enregistrer un commentaire