国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

控制臺不斷輸入數字,輸入end的時候輸出最大值

2019-11-08 01:45:41
字體:
來源:轉載
供稿:網友

找了幾個方法都是把max初值設置為0,然后繼續(xù)后面的步驟.覺得不妥.自己寫了個.沒想到代碼行數這么多,看了幾遍,沒什么好改的地方,暫時這么貼著吧

個人覺得輸入校驗用正則比較方便.

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Text.RegularExPRessions;namespace sln20170220{    class Program    {        static void Main(string[] args)        {            bool b = true;            int max;            int a;            Console.WriteLine("請輸入數組或者end退出");            string str  = Console.ReadLine().Trim();            while (!isNumber(str))            {                if (str.ToLower() =="end")                {                    return;                }                Console.WriteLine("請輸入正確的數字或者輸入end退出");                str = Console.ReadLine().Trim();            }            max = Convert.ToInt32(str);            while (b)            {                str = Console.ReadLine().Trim();                if (str.ToLower() == "end")                {                    Console.WriteLine("最大值是{0}",max);                    b=false;                                    }                else                {                    if (isNumber(str))                    {                        a = Convert.ToInt32(str);                        max = a > max ? a : max;                    }                    else                    {                        Console.WriteLine("請輸入正確的數字或者輸入end退出");                    }                }            }            Console.ReadKey();        }        private static bool isNumber(string str)        {            Regex reg = new Regex("^[0-9]+$");            Match ma = reg.Match(str);            return ma.Success ? true : false;        }    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 泸州市| 甘谷县| 剑阁县| 汾阳市| 石首市| 车险| 凤城市| 乌鲁木齐县| 玛多县| 南召县| 绥化市| 永宁县| 丰顺县| 枣强县| 柯坪县| 鄂托克旗| 苗栗市| 普陀区| 嘉兴市| 卫辉市| 遂溪县| 仁寿县| 公安县| 杭锦旗| 凤山市| 康定县| 公主岭市| 平泉县| 中宁县| 桦甸市| 西和县| 宜章县| 清丰县| 西城区| 阿鲁科尔沁旗| 宁城县| 游戏| 贺兰县| 郓城县| 青神县| 莒南县|