·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 黑马程序员-ReadInt

黑马程序员-ReadInt

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

黑马程序员-ReadInt

  判断输入的字符串是否为数字。

namespace读入一个整数

{

classPRogram

{

staticvoidMain(string[]args)

{

Console.WriteLine("请输入你的年龄!");

intage=ReadInt();

Console.WriteLine("你刚刚输入的年龄为"+age);

Console.WriteLine("请输入你是哪一年出生的?");

intyear=ReadInt();

Console.WriteLine("噢,你是{0}年出生的呀!",year);

Console.WriteLine("请输入你们班有多少人?");

intcount=ReadInt();

Console.WriteLine("你们班有{0}人",count);

Console.ReadKey();

}

publicstaticintReadInt()

{

intnumber=0;

do

{

try

{

number=Convert.ToInt32(Console.ReadLine());

returnnumber;

}

catch

{

Console.WriteLine("输入有误,请重新输入!");

}

}while(true);

}

}

}