回覆列表
  • 1 # 錢布斯

    using System.Text.RegularExpressions;

    string a = "";

    string b = "";

    string c = "";

    string d = "";

    int max1 = 0;

    int max2 = 0;

    int max = 0;

    a = Console.ReadLine();

    while (!IsNum(a))

    {

    Console.WriteLine("非數字,請重新輸入。");

    a = Console.ReadLine();

    }

    b = Console.ReadLine();

    while (!IsNum(b))

    {

    Console.WriteLine("非數字,請重新輸入。");

    b = Console.ReadLine();

    }

    c = Console.ReadLine();

    while (!IsNum(c))

    {

    Console.WriteLine("非數字,請重新輸入。");

    c = Console.ReadLine();

    }

    d = Console.ReadLine();

    while (!IsNum(d))

    {

    Console.WriteLine("非數字,請重新輸入。");

    d = Console.ReadLine();

    }

    max1 = Convert.ToInt32(a) > Convert.ToInt32(b) ? Convert.ToInt32(a) : Convert.ToInt32(b);

    max2 = Convert.ToInt32(c) > Convert.ToInt32(d) ? Convert.ToInt32(c) : Convert.ToInt32(d);

    max = max1 > max2 ? max1 : max2;

    Console.WriteLine("最大數是:{0}", max);

    Console.WriteLine("按任意鍵退出!");

    Console.ReadLine();

    }

    public static bool IsNum(string s)

    {

    return Regex.IsMatch(s, @"^\d+");

    }

    記事本寫的..未測試...

  • 中秋節和大豐收的關聯?
  • 客廳裝修做半吊頂用什麼材料、什麼造型好?