為什么我運(yùn)行那里老是運(yùn)行失敗啊,但輸出了結(jié)果,卻運(yùn)行失敗。
你們看下我的代碼有什么錯(cuò)誤嗎。
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
??????????? //聲明整型數(shù)組,保存一組整數(shù)
??????????? int[] num = new int[] {3,34,42,2,11,19,30,55,20};
??????????????? for(int i=0;i<=num.Length;i++)
??????????? {
???????????????????? if(num[i]%2==0)
??????????????? {
??????????????????? Console.Write(num[i]+",");
??????????????? }
??????????? }//請完善代碼,循環(huán)打印數(shù)組中的偶數(shù)
??????? }
??? }
}
2020-08-10
?for(int i=0;i<=num.Length;i++)? ? ? ?中的<=? 換成<
2020-07-23
for(int i=0;i<=num.Length;i++)? 這里不是等于號? ,而是小于號 ,因?yàn)閕是從0開始的
2020-05-31
num.Length是元素總數(shù),正好比最大索引大1,所以要用<? ?2.不對齊只是不美觀,不會影響運(yùn)行,但最好還是要注意對齊問題
2020-05-04
第一、數(shù)組的索引超出了數(shù)組的邊界,循環(huán)那里<=時(shí),訪問0 1 2 3 4 5 6 7 8 9共十個(gè),超出數(shù)組邊界,這個(gè)條件應(yīng)改為<。
第二,注意For循環(huán)和if判斷的括號的對齊位置。