Guest User

Untitled

a guest
Oct 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace exception_numbers
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string s = Console.ReadLine();
  13.             string[] arr = s.Split(' ');
  14.            
  15.             try
  16.             {
  17.                 for (int i = 0; i < arr.Length; i++)
  18.                 {
  19.                     Console.Write(arr[i] + " ");
  20.                     double n = double.Parse(arr[i]);
  21.                     if (n <= 0)
  22.                         throw new Exception();
  23.                    // OK, прекрасная идея, но лучше бросать, да и ловить не Exception вообще,
  24.                    // а что-нибудь специализированное, например FormatException
  25.                 }
  26.                 Console.WriteLine("Да");
  27.             }
  28.             catch (Exception)
  29.             {
  30.                 Console.WriteLine("Нет");
  31.             }
  32.  
  33.             Console.ReadKey();
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment