题解 | #牛牛的空格分隔#
牛牛的空格分隔
https://www.nowcoder.com/practice/b2203c4a5c304536a7f577bc885de511
包含了对异常产生的检测和原因说明
using System; public class Program { public static void Main() { String[] s = new String[3]; int i = 0; // 读取三个字符串 while (i < 3) { s[i] = Console.ReadLine(); i++; } // 检查第三个字符串是否为 null if (s[2] == null) { Console.WriteLine("Third string is null."); } else { try { double number = double.Parse(s[2]); Console.WriteLine("{0} {1} {2:0.000000}", s[0], s[1], number); } catch (FormatException ex) { Console.WriteLine("Format exception: " + ex.Message); } catch (OverflowException ex) { Console.WriteLine("Overflow exception: " + ex.Message); } } } }