-1
배열의 모든 단어에서 모든 모음을 삭제하고 싶습니다. 그래서이 함께했다 : 나는, 나는이 하나가 최고 였는데, 아직도 내가이 일을 할 수없는 시도 모든 옵션에서루프 내부의 루프/바꾸기가 작동하지 않습니다
public class AnotherExercise {
public static void main (String[] args){
String[] intruments = {"cello", "guitar", "violin", "double bass"}; //the array of words
String[] vowels = {"a", "e", "i", "o", "u"}; // the array of vowels
String[] intruments2 = new String[5]; //the array of wrods without vowels
String nothing = ""; // used to replace a vowel to nothing
for (int i = 0; i < 4; i++){ // first for loop to go through all of the intruments
for(int e = 0; e < 5; e++){ //second for loop to go through all the vowels
intruments2[i] = intruments[i].replaceAll(vowels[e], nothing); //replacing vowels
//and storing them in a new array
}
System.out.println(intruments2[i]); //outputting the words without vowels
}
}
}
, 그것은 출력 :
cello
gitar
violin
doble bass
을 내 의견에 이상한 부분은 "u"를 대체한다는 것입니다. 어리석은 실수 일지 모르지만 나는 그것을 이해할 수 없다.
이것은 대단히 비효율적입니다. 단어마다 모음 하나당 하나의 검색을 수행하는 대신 수동으로 문자를 반복하여 모음에 대해 테스트 해보십시오. 또는 하나의 regex replace를 사용하여 모든 모음을 지우십시오. –