課程
/后端開發(fā)
/Java
/Java入門第三季
為什么我這會拋出異常?
2015-04-30
源自:Java入門第三季 2-4
正在回答
string index out
檢查下你的變量i的取值范圍是否超出字符串length
btw,when you ask questions pls show all the codes?
int num = 0;
String string = "aabcdefgasshhrhaggggjdca";
for(int i = 0;i<string.length(); i++){
if(string.charAt(i)=='a'){
num++;
}
System.out.println(num);
舉報
Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧
4 回答為什么用if ( s.charAt(i)=='a' )不能編譯,
2 回答為什么不能這樣寫 if ((s.charAt(i)).equals('a'))
2 回答if (s.charAt(i)=='a') 為什么不用“” 而是用''
5 回答各位大神,題目是:統(tǒng)計指定字符串中字符 ‘a’ 出現(xiàn)的次數(shù)...為什么if ( s[i]=="a") 不可以,要改成if(s.charAt(i))=='a')????
6 回答 for(int i = str.length()-1;i>3;i-3)報錯error: not a statement
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2015-12-05
string index out
檢查下你的變量i的取值范圍是否超出字符串length
btw,when you ask questions pls show all the codes?
2015-04-30
int num = 0;
String string = "aabcdefgasshhrhaggggjdca";
for(int i = 0;i<string.length(); i++){
if(string.charAt(i)=='a'){
num++;
}
}
System.out.println(num);