最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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(綜合應用)的評論 (共 條)

分享到微博請遵守國家法律
青河县| 城市| 开江县| 韶山市| 轮台县| 楚雄市| 大同县| 新巴尔虎左旗| 平定县| 河津市| 盈江县| 买车| 广安市| 博乐市| 滨海县| 油尖旺区| 钦州市| 镇安县| 青河县| 开原市| 太保市| 竹溪县| 吴川市| 沂水县| 呼伦贝尔市| 塘沽区| 交口县| 广德县| 南部县| 扎鲁特旗| 日喀则市| 莆田市| 调兵山市| 黄山市| 当雄县| 阜康市| 固始县| 建湖县| 南昌市| 积石山| 翼城县|