国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

方法/函數(shù)8(綜合應用)

2023-01-27 15:19 作者:此城過客  | 我要投稿

static int Getnumber(string s)//第一個自定義函數(shù),判斷輸入的字符是否合規(guī)

{

? ? ? ? while (true)

? ? ? ? {

? ? ? ?? ? ? ? try

? ? ? ? ? ? ?? {

? ? ? ? ? ? ? ? ? ? ? ?int number = Convert.ToInt32(s);//如果輸入的是字母,那么就轉變不了

? ? ? ? ? ? ? ? ? ? ? ?return number;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? catch?

? ? ? ? ? ? ? ? {?

? ? ? ? ? ? ? ? ? ? ???Console.WriteLine("輸入有誤??!請重新輸入") ;//如果輸入的是字母,那么就? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//會執(zhí)行這個

? ? ? ? ? ? ? ? ? ? ? ?s = Console.ReadLine();

? ? ? ? ? ? ? ? ?}

? ? ? ? }

}

static?void Judgenumber(ref int n1, ref int n2)//第二個自定義函數(shù),判斷輸入的第二個數(shù)是不? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//是比第一個數(shù)大

{

? ? ? ? ?if (n1 < n2)

? ? ? ? ?{

? ? ? ? ? ? ? ? return;

? ? ? ? ? }

? ? ? ? ? else?

? ? ? ? ? {

? ? ? ? ? Console.WriteLine("第一個數(shù)字不能大于或者等于第二個數(shù)字,請重新輸入??!");

? ? ? ? ? string s1 = Console.ReadLine();

? ? ? ? ? n1 = Getnumber(s1);

? ? ? ? ? Console.WriteLine("請重新輸入第二個數(shù)字");

? ? ? ? ? string s2 = Console.ReadLine();

? ? ? ? ? n2 = Getnumber(s2);

? ? ? ? ? }

}

static int Getsum(int num1,int num2)//第三個自定義函數(shù),計算兩個數(shù)之間所有數(shù)的和

{

? ? ? ? ? int sum = 0;

? ? ? ? ? for (int i = num1; i < num2 + 1; i++)

? ? ? ? ? { sum += i ;?}

? ? ? ? ? return sum;

}

static void Main(string[] args)

{

? ? ? ? ?Console.WriteLine("請輸入第一個數(shù)");

? ? ? ? ?string str = Console.ReadLine();

? ? ? ? ?int str1 = Getnumber(str);//引用第一個函數(shù)

? ? ? ? ?Console.WriteLine("請輸入第二個數(shù)");

? ? ? ? ?string stra = Console.ReadLine();

? ? ? ? ?int str2 = Getnumber(stra);//引用第二個函數(shù)

? ? ? ? ?Judgenumber(ref str1,ref str2);//判斷第二個數(shù)是否大于第一個數(shù)

? ? ? ? ?int sum = Getsum(str1, str2);//計算兩個數(shù)之間的和

? ? ? ? ?Console.WriteLine("這兩個數(shù)累加的和是:"+sum);

}??


方法/函數(shù)8(綜合應用)的評論 (共 條)

分享到微博請遵守國家法律
渝北区| 白水县| 桦南县| 高台县| 井陉县| 锦屏县| 穆棱市| 信宜市| 峨山| 灵山县| 临洮县| 七台河市| 鄱阳县| 双流县| 尤溪县| 万宁市| 潼关县| 义乌市| 沈丘县| 城口县| 长丰县| 五河县| 长春市| 兴隆县| 辉南县| 香河县| 乌鲁木齐市| 菏泽市| 长兴县| 英吉沙县| 惠东县| 隆尧县| 娄烦县| 东丽区| 锡林浩特市| 彰化县| 南部县| 和龙市| 香格里拉县| 红原县| 山阴县|