Zi 字媒體
2017-07-25T20:27:27+00:00
jash.liao的JAVA整理教學:JAVA控制結構-多重選擇結構(switch)
線上執行:http://www.tutorialspoint.com/compile_java_online.php / http://www.compilejava.net/
code2html:http://tohtml.com/
publicclass HelloWorld{
/*C語言的switch只能數字,JAVA比較靈活*/
publicstaticvoid main(String[]args){
String saying ="Never put off till tomorrow what you can do today.";
int aV, eV, iV, oV, uV, other, i;
aV = eV = iV = oV = uV = other = i =0;
while(saying.charAt(i)!='.'){
switch(saying.charAt(i)){
case'A':
case'a':
aV++;
break;
case'E':
case'e':
eV++;
break;
case'I':
case'i':
iV++;
break;
case'O':
case'o':
oV++;
break;
case'U':
case'u':
uV++;
break;
default:
other++;
break;
}
i++;
}
System.out.println("a: "+ aV +", e: "+ eV +", i: "+ iV +", o: "+ oV +", u: "+ uV +", other: "+ other);
}
}
寫了
5860316篇文章,獲得
23313次喜歡