目的:
包含不返回任何内容或我使用错误
Scanner out = new Scanner(System.in);
System.out.print("Please insert a text: ");
String[] vowels = {"a", "e", "i", "o", "u"};
String userInput = out.nextLine();
char[] charUserInput = userInput.toCharArray();
String temp = "";
String temp1 = "";
for (int i = 0; i <= charUserInput.length -1; i++){
if (Character.isLetter(charUserInput[i])){
if (Character.toString(charUserInput[i]).equalsIgnoreCase(vowels[0]) || (Character.toString(charUserInput[i]).equalsIgnoreCase(vowels[1]) ||
(Character.toString(charUserInput[i]).equalsIgnoreCase(vowels[2]) || (Character.toString(charUserInput[i]).equalsIgnoreCase(vowels[3]) ||
(Character.toString(charUserInput[i]).equalsIgnoreCase(vowels[4])))))){
if (!Character.toString(charUserInput[i]).contains(temp)){
temp += Character.toString(charUserInput[i]);
}
}else{
if (!Character.toString(charUserInput[i]).contains(temp1)){
temp1 += Character.toString(charUserInput[i]);
}
}
}
}
System.out.println(temp);
System.out.println(temp1);
out.close();
答案 0 :(得分:2)
看起来你倒置了条件:使用
temp.contains(Character.toString(charUserInput[i]))
而不是
Character.toString(charUserInput[i]).contains(temp)