課程
/后端開發(fā)
/C#
/C#開發(fā)輕松入門
幫幫看看代碼問(wèn)題在哪?謝謝
2020-08-13
源自:C#開發(fā)輕松入門 5-8
正在回答
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,43,2,11,19,30,55,20};
? ? ? ? ? ? foreach(int x in num)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(x%7==0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write("有7的整倍數(shù)");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? Console.Write("沒(méi)有7的整倍數(shù)");
? ? ? ? ? ? }//請(qǐng)完善代碼,判斷數(shù)組中有沒(méi)有7的整倍數(shù)
? ? ? ? ? ??
? ? ? ? }
? ? }
}//我覺(jué)得還是這個(gè)簡(jiǎn)單點(diǎn)
在 Console.Write 下面加上 break; 執(zhí)行一次 跳出就 ok了
?if(has7)
? ? ? ? ? ? ? ? ? ? Console.Write("有7的整數(shù)倍");
? ? ? ? ? ? ? ? ? ?Console.Write("沒(méi)有7的整數(shù)倍");??
這段代碼需要放在for循環(huán)之外;
放在循環(huán)里面,每次校驗(yàn)時(shí)都會(huì)執(zhí)行,而我們只需要執(zhí)行一次
? ? ? ? ? ? //請(qǐng)完善代碼,判斷數(shù)組中有沒(méi)有7的整倍數(shù)
? ? ? ? ? ? bool has7 = false;
? ? ? ? ? ? for(int i=0;i<num.length;i++)
? ? ? ? ? ? ? ? if(num[i] %7==0)
? ? ? ? ? ? ? ? ? ? has7 = true;
? ? ? ? ? ? ? ? if(has7)
? ? ? ? ? ? }
}
舉報(bào)
本門課程是C#語(yǔ)言的入門教程,將帶你輕松入門.NET開發(fā)
1 回答點(diǎn)進(jìn)去求解
1 回答求助???
6 回答請(qǐng)大神指點(diǎn)
2 回答請(qǐng)大佬解惑!
5 回答此題不太理解,求大神指點(diǎn)。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2021-05-07
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,43,2,11,19,30,55,20};
? ? ? ? ? ? foreach(int x in num)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(x%7==0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write("有7的整倍數(shù)");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write("沒(méi)有7的整倍數(shù)");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }//請(qǐng)完善代碼,判斷數(shù)組中有沒(méi)有7的整倍數(shù)
? ? ? ? ? ??
? ? ? ? }
? ? }
}//我覺(jué)得還是這個(gè)簡(jiǎn)單點(diǎn)
2021-05-07
在 Console.Write 下面加上 break; 執(zhí)行一次 跳出就 ok了
2020-11-04
?if(has7)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write("有7的整數(shù)倍");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ?Console.Write("沒(méi)有7的整數(shù)倍");??
? ? ? ? ? ? ? ? }
這段代碼需要放在for循環(huán)之外;
放在循環(huán)里面,每次校驗(yàn)時(shí)都會(huì)執(zhí)行,而我們只需要執(zhí)行一次
2020-08-13
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,43,2,11,19,30,55,20};
? ? ? ? ? ? //請(qǐng)完善代碼,判斷數(shù)組中有沒(méi)有7的整倍數(shù)
? ? ? ? ? ? bool has7 = false;
? ? ? ? ? ? for(int i=0;i<num.length;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(num[i] %7==0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? has7 = true;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if(has7)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write("有7的整數(shù)倍");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ?Console.Write("沒(méi)有7的整數(shù)倍");??
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}