輸出結(jié)果文字的文字重復(fù),我的錯(cuò)在哪里?
結(jié)果:
循環(huán)輸出數(shù)組中元素的值:sports
循環(huán)輸出數(shù)組中元素的值:game
循環(huán)輸出數(shù)組中元素的值:movie
? ? ? ? ? public static void main(String[] args) {
? ? ? ? ? ? ? ?? String[] hobbys = {"sports", "game", "movie" };
? ? ? ? ? ? ? ?? for(int i=0;i<hobbys.length;i++){
? ? ? ? ? ? ? ?? System.out.println("循環(huán)輸出數(shù)組中元素的值:"+hobbys[i]);?? ? ?
? ? ? ? ? ? ?? }
? ? ? ?? }
??? }
2018-10-27
你的代碼,文字信息在for循環(huán)內(nèi),執(zhí)行時(shí)會(huì)遍歷輸出,將文字語句在for循環(huán)外即可: