最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么if下面加了畫(huà)括號(hào)會(huì)錯(cuò)誤


static void Main(string[] args)

? ? ? ? {

? ? ? ? ? ? int x = 1;

? ? ? ? ? ? int sum = 0;//和,初始化為0

? ? ? ? ? ? while (x <= 30)//循環(huán)條件

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (x%2!=0)//篩選條件

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? sum += x;

? ? ? ? ? ? ? ? x++;

? ? ? ? ? ? ? ? }??

? ? ? ? ? ? }? ?

? ? ? ? ? ? Console.Write("1-30奇數(shù)的和:"+sum);

? ? ? ? }


正在回答

3 回答

?x++; 在if的執(zhí)行語(yǔ)句里,當(dāng)x的值為偶數(shù)時(shí),if語(yǔ)句不執(zhí)行,x的值一直不加1,while (x <= 30)一直執(zhí)行,程序進(jìn)入死循環(huán)。


0 回復(fù) 有任何疑惑可以回復(fù)我~

你的花括號(hào)位置加錯(cuò)了,x++屬while的程序,不屬于if,所以花括號(hào)不應(yīng)該包含x++。

using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
??????????? int x = 1;
??????????? int sum = 0;//和,初始化為0
??????????? while (x <= 30)//循環(huán)條件
??????????? {
??????????????? if (x%2!=0)//篩選條件
??????????????? {??? sum += x;
??????????????? }

??????????????? x++;
??????????? }
??????????? Console.Write("1-30奇數(shù)的和:"+sum);
??????? }
??? }
}

0 回復(fù) 有任何疑惑可以回復(fù)我~

輸入法的問(wèn)題吧,用英文狀態(tài)的花括號(hào),語(yǔ)法沒(méi)得問(wèn)題,但是X++放在if里面要陷入死循環(huán)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么if下面加了畫(huà)括號(hào)會(huì)錯(cuò)誤

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)