We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 16: Exceptions - String to Integer
Day 16: Exceptions - String to Integer
Sort by
recency
|
1011 Discussions
|
Please Login in order to post a comment
My JS solution:
string S = Console.ReadLine();
Console.WriteLine(S.Any(c=> !(c >= 48 && c <= 57) || c==' ')?"Bad String":S);
Console.WriteLine(Int32.TryParse(S, out int result)?result:"Bad String");
I'm using swift, and getting the same error over and over, did anyone knows how to solve it?
this is meu received error: Compiler Message Error reading result file.You should use exception handling concepts.
and this is my working code:
I had to remove the "if name == 'main':"
!/bin/python3
import math import os import random import re import sys if name == 'main': try: S = input() result = int(S) print(result) except ValueError: print("Bad String") except Exception: print("Bad String")