您的位置:首页 > 其它

将百分制转换为五分制,如果输入的百分制成绩超出0~100时,程序抛出异常。

2013-04-18 14:41 316 查看
将百分制转换为五分制,如果输入的百分制成绩超出0~100时,程序抛出异常。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace CSharp
{
class Program
{
static void Main(string[] args)
{
while (true)
{
double num, num2;
string s;
Console.WriteLine("输入:x%,例如40%");
s = Console.ReadLine();
s = s.Substring(0, s.Length - 1);
num = double.Parse(s);
num2 = (5 * num) / 100;

if (num > 100 || num < 0)
{
try
{
throw new Exception();
}
catch (Exception ex) {
Console.WriteLine("error");
}
}
else
Console.WriteLine(num2 + "/5");
}
Console.ReadKey();
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐