相关疑难解决方法(0)

如果给定的字符串与某些格式不匹配,会引发哪个异常?

这是对旧问题的跟进.

给定一个ISBN号,例如3-528-03851-5,如果传入的字符串与格式X-XXX-XXXXX-X不匹配,我应该提出哪种例外类型?

python exception-handling

3
推荐指数
1
解决办法
1868
查看次数

Isbn 生成校验位

此代码验证 ISBN 是否有效。对于九位数字输入,我想通过计算和附加校验位来形成有效的 ISBN。对于少于九位数的输入,我希望它返回错误消息“请输入正确的数字”。我该怎么办?

   public class isbn
    {   //attributes
         private string isbnNum;
         //method   
         public string GetIsbn()
         {
             return this.isbnNum;
         }
           //constructor
           public isbn()
           {
               Console.Write("Enter Your ISBN Number: ");
               this.isbnNum = Console.ReadLine();

           }//end default constructor

            //method
           public string displayISBN()
           {

               return  this.GetIsbn();

           }


       public static void Main(string[] args)
        {
            //create a new instance of the ISBN/book class

            isbn myFavoriteBook = new isbn();

            //contains the method for checking validity 
            bool isValid = CheckDigit.CheckIsbn(myFavoriteBook.GetIsbn());

            //print out the results of the validity.
            Console.WriteLine(string.Format("Your …
Run Code Online (Sandbox Code Playgroud)

c# c#-3.0

1
推荐指数
1
解决办法
4738
查看次数

标签 统计

c# ×1

c#-3.0 ×1

exception-handling ×1

python ×1