1. 程式人生 > >藍橋杯:判定字元位置

藍橋杯:判定字元位置

題目描述

返回給定字串s中母音字母的首次出現位置。英語母音字母只有‘a’、‘e’、‘i’、‘o’、‘u’五個。 
若字串中沒有母音字母,則返回0。 
只考慮小寫的情況。 

輸入

輸出

樣例輸入

and 

樣例輸出

1

程式設計程式碼如下:

Scanner sc = new Scanner(System.in);

String str = sc.nextLine();

char[] c = new char[str.length()];

for(int i=0;i<str.length();i++){

c[i] = str.charAt(i);

if(c[i]=='a'||c[i]=='e'||c[i]=='i'||c[i]=='o'||c[i]=='u'){

System.out.println(i+1);

return;

}

}

System.out.println("0");