c#语言。编一个程序,从键盘上输入三个数,把最大数找出来。

我是初学者 控制台的程序

using System;
 
namespace ConsoleMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, max = int.MinValue;
            Console.WriteLine("请输入3个数:");
            for (int i = 0; i < 3; i++)
            {
                x = int.Parse(Console.ReadLine());
                if (x > max) max = x;
            }
            Console.WriteLine("最大数为:{0}", max);
        }
    }
}

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-04-17
int x, y, z, max, t;
x = int.Parse(Console.ReadLine());
y = int.Parse(Console.ReadLine());
z = int.Parse(Console.ReadLine());
t = Math.Max(x, y);
max = Math.Max(t, z);

使用Math类中的Max方法,可以不用循环实现
第2个回答  2014-04-17
用Math.Max(byte val1,byte val2)进行两次对比
相似回答