C#在原程序找到的最小整数数据类型
原程序如下:(如果原程序有问题,请指出)longmyLong;myLong=Convert.ToInt64(Console.ReadLine());if(myLong<i...
原程序如下: (如果原程序有问题, 请指出) long myLong;
myLong = Convert.ToInt64(Console.ReadLine());
if (myLong < int.MaxValue)
{
Console.WriteLine(myLong + " is less than " + int.MaxValue + " so it will not overflow an int.");
}
else
{
Console.WriteLine(myLong + " is more than " + int.MaxValue + " so it will overflow an int.");
} 要求加强该程序找到的最小整数数据类型(byte, short, int 和 long),值不会溢出 展开
myLong = Convert.ToInt64(Console.ReadLine());
if (myLong < int.MaxValue)
{
Console.WriteLine(myLong + " is less than " + int.MaxValue + " so it will not overflow an int.");
}
else
{
Console.WriteLine(myLong + " is more than " + int.MaxValue + " so it will overflow an int.");
} 要求加强该程序找到的最小整数数据类型(byte, short, int 和 long),值不会溢出 展开
1个回答
2014-01-22
展开全部
既然是long型,比较的时候当然也要是long.MaxValue long myLong;
myLong = Convert.ToInt64(Console.ReadLine());
if (myLong < long.MaxValue)
{
Console.WriteLine(myLong + " is less than " + long.MaxValue + " so it will not overflow an long.");
}
else
{
Console.WriteLine(myLong + " is more than " + long.MaxValue + " so it will overflow an long.");
}
Console.Read();这样就可以了
myLong = Convert.ToInt64(Console.ReadLine());
if (myLong < long.MaxValue)
{
Console.WriteLine(myLong + " is less than " + long.MaxValue + " so it will not overflow an long.");
}
else
{
Console.WriteLine(myLong + " is more than " + long.MaxValue + " so it will overflow an long.");
}
Console.Read();这样就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询