111,126
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
namespace kehou1
{
class Program
{
static void Main(string[] args)
{
int cTemp;
lbstart:
try
{
System.Console.Write("請輸入字母:");
cTemp = System.Console.ReadLine()[0];
if (cTemp >= 'a' && cTemp <= 'z')
ShowToUpper(cTemp);
else if (cTemp >= 'A' && cTemp <= 'Z')
ShowToLower(cTemp);
else
{
throw new MyException("異常情況!");
}
}
catch (Exception ex1)
{
System.Console.WriteLine("{0}", ex1.Message);
goto lbstart;
}
}
public static void ShowToUpper(int cTemp)
{
char sTemp = (char)(cTemp - 32);
System.Console.WriteLine("{0}", sTemp);
}
public static void ShowToLower(int cTemp)
{
char sTemp = (char)(cTemp + 32);
System.Console.WriteLine("{0}", sTemp);
}
public class MyException : ApplicationException
{
public MyException(string strMsg)
: base(strMsg)
{
}
}
}
}
static void Main(string[] args)
{
int cTemp;
while(true)
{
try
{
System.Console.Write("请输入字母:");
cTemp = System.Console.Read();
if (cTemp >= 'a' && cTemp <= 'z')
ShowToUpper(cTemp);
else if (cTemp >= 'A' && cTemp <= 'Z')
ShowToLower(cTemp);
else
{
throw new MyException("异常情况!");
}
break;
}
catch (Exception ex1)
{
System.Console.WriteLine("{0}",ex1.Message);
}
}
}