我感覺挺對的啊,卻一直顯示不正確
?static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? //聲明整型數(shù)組,保存一組整數(shù)
? ? ? ? ? ? int[] num = new int[] { 3,34,43,2,11,19,30,55,20};
? ? ? ? ? ? bool hasNbei =false; //請完善代碼,判斷數(shù)組中有沒有7的整倍數(shù)
? ? ? ? ? ? foreach (int x in num)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(x%7==0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? hasNbei=true;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if(hasNbei)
? ? ? ? ? ? ? ? ? Console.WriteLine("有7的整數(shù)倍");
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? Console.WriteLine("沒有7的整數(shù)倍");
? ? ? ? ? ? }
2022-10-08
整數(shù)倍改成整倍數(shù)
2016-11-08
不對嗎?你這個寫法運行沒問題啊
2016-11-04
static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? //聲明整型數(shù)組,保存一組整數(shù)
? ? ? ? ? ? int[] num = new int[] { 3,34,43,2,11,19,30,55,20};
? ? ? ? ? ? bool hasNbei =false; //請完善代碼,判斷數(shù)組中有沒有7的整倍數(shù)
? ? ? ? ? ? foreach (int x in num)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(x%7==0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? hasNbei=true;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }//添加大括號,限制foreach作用范圍
? ? ? ? ? ? ? ? if(hasNbei)
? ? ? ? ? ? ? ? ? Console.WriteLine("有7的整數(shù)倍");
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? Console.WriteLine("沒有7的整數(shù)倍");
? ? ? ? ? ? }
2016-11-04
邏輯錯誤。
判斷hasNbei的語句應(yīng)寫在foreach語句之外,意思就是把數(shù)組中所有元素檢查完之后再去判斷hasNbei的真假