으로 읽어들입니다. 도움이 필요해. 저는 사용자가 텍스트를 입력하고, 텍스트를 반대로하고, 텍스트의 모음 수를 읽고, 역행 된 텍스트에 얼마나 많은 모음이 있는지 알려주고 있습니다.자바 문자열의 모음 수를
public static void main(String[] args)
{
System.out.println ("Please type in whatever you want ");
Scanner type_input = new Scanner (System.in);
Scanner type_input = new Scanner (System.in);
StringBuilder type_output = new StringBuilder();
type_output.append(type_hold);
type_output=type_output.reverse();
System.out.println("Is this what you types in? " + type_output);
for(int vowel_num = 0; vowel_num< type_hold.length(); vowel_num++)
{
if((type_hold.charAt(vowel_num) =='a')||(type_hold.charAt(vowel_num) =='e')||
(type_hold.charAt(vowel_num) =='o')||(type_hold.charAt(vowel_num) =='i')||
(type_hold.charAt(vowel_num) =='u')){
System.out.println("There are " + vowel_num + " vowels in " + type_hold);
}
하지만 실행시 입력 할 때 다음과 같이 표시됩니다. 내가 어디서 엉망인지 모르겠다.
run:
Please type in whatever you want
hello
Is this what you types in? olleh
There are 1 vowels in hello
There are 4 vowels in hello
편집 : 알아 냈습니다. 도와 주신 모든 분들께 감사드립니다!
나는 반전 된 텍스트 모음의 수는 원래 텍스트에서 모음의 수와 동일하다는 걸거야 ... – ajb
@ajb 나는 그 의견에 좋은 웃음을 가지고 있었다. 그러나 나는 그가 여기에 2 개의 연습 과제를 가지고 있다고 생각한다. - 텍스트를 역순으로 바꾸고 모음을 세어 라. 나는 그가 원래의 *와 * 역전 된 텍스트로 그들을 세우려고했다고 생각하지 않는다. –
왜'type_input ='라인이 두 번입니까? 다른 문제는 'vowel_num'이 값의 수를 세지 않고 오히려 그 위치를 제공한다는 것입니다. –