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