Advertisement
minnera

#30daysofcode # day16

Oct 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. //https://www.hackerrank.com/challenges/30-exceptions-string-to-integer/problem
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. class Solution {
  8.  
  9.     static void Main(String[] args) {
  10.         string S = Console.ReadLine();
  11.         int i = 0;
  12.         try{
  13.           i = int.Parse(S);
  14.           Console.WriteLine(i);
  15.         }
  16.         catch(FormatException fe){
  17.           Console.WriteLine("Bad String");
  18.         }
  19.         catch(Exception e){
  20.           Console.WriteLine("Bad String");
  21.         }
  22.        
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement