从键盘输入一串整数,按数字的相反顺序输出
2015-08-30 12:47
531 查看
class Program
{
static void Main(string[] args)
{
Sort s1 = new Sort();
while (true)
{
Console.WriteLine("请输入一组小于10位的数字,将会逆序打印");
s1.InputNum();
if (!s1.Judge()) break;
Console.WriteLine();
}
Console.ReadKey();
}
}
class Sort
{
//输入的方法
public void InputNum(){
//存储输入的字符串
string s = Console.ReadLine();
//存储转换后的数字
int i = 0;
//判断是不是数字串
bool isNum = false;
if (int.TryParse(s, out i))//将字符串转换成整数 返回布尔型 转换成功返回true 转换失败返回false
{
int nextNum = i;
int thisNum = 0;
Console.Write("输出结果是:");
for (int j = 0; j < s.Length; j++)
{
thisNum = nextNum % 10;
nextNum = nextNum / 10;
Console.Write(thisNum);
}
Console.WriteLine();
}
else {
Console.WriteLine("输入的不是一串数字");
}
}
//判断是否继续输入
public bool Judge()
{
Console.WriteLine("是否继续输入:(Y/N)");
string c = Console.ReadLine();
c = c.ToUpper();
if (c == "Y") {
return true;
}
else if (c == "N")
{
return false;
}
else {
Console.WriteLine("输入错误");
return false;
}
}
}
{
static void Main(string[] args)
{
Sort s1 = new Sort();
while (true)
{
Console.WriteLine("请输入一组小于10位的数字,将会逆序打印");
s1.InputNum();
if (!s1.Judge()) break;
Console.WriteLine();
}
Console.ReadKey();
}
}
class Sort
{
//输入的方法
public void InputNum(){
//存储输入的字符串
string s = Console.ReadLine();
//存储转换后的数字
int i = 0;
//判断是不是数字串
bool isNum = false;
if (int.TryParse(s, out i))//将字符串转换成整数 返回布尔型 转换成功返回true 转换失败返回false
{
int nextNum = i;
int thisNum = 0;
Console.Write("输出结果是:");
for (int j = 0; j < s.Length; j++)
{
thisNum = nextNum % 10;
nextNum = nextNum / 10;
Console.Write(thisNum);
}
Console.WriteLine();
}
else {
Console.WriteLine("输入的不是一串数字");
}
}
//判断是否继续输入
public bool Judge()
{
Console.WriteLine("是否继续输入:(Y/N)");
string c = Console.ReadLine();
c = c.ToUpper();
if (c == "Y") {
return true;
}
else if (c == "N")
{
return false;
}
else {
Console.WriteLine("输入错误");
return false;
}
}
}
相关文章推荐
- Springmvc中 同步/异步请求参数的传递以及数据的返回
- JProfiler 入门教程(提供下载PDF)
- javascript中的正则表达式使用详解
- java初学习
- EasyUI常用控件禁用方法
- 手势密码(二)
- sprintf sscanf
- 你知道如何写一个框架吗?
- 全文搜索服务器solr之客户端 - solrj二次开发
- 二维数组中的查找
- xcode单词及回调
- C#基础案例------聊天机器人
- nRF24L01模块使用(待完成)
- 源码安装apache2
- Eclipse方便的管理Tomcat (Eclipse + WTP + Tomcat 配置 )
- Android Studio 实现真机截图和短视频录制
- solrJ使用样例
- Solr使用初探——SolrJ的使用
- Disply和Visibility的区别
- Linux系统管理-(3)-Inode