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
+ 0 comments For Javascript, I'm also trying to solve this by try catch but it is very very basic concept. You do not need to use that, it solved by using isNAN() method and print the output accordingly.
it can be soved by simply this one below line :
console.log( isNaN(S) ? "Bad String" : S);
+ 0 comments Python 3
Just clear everythig else previously given i.e. all the import statements and if name==..
s = input() try: print(int(s)) except ValueError: print("Bad String")
+ 1 comment I don't konw what is the problem of this
try: print(int(S)) except ValueError: print("Bad String")
result: Error reading result file.You should use exception handling concepts.
I
+ 0 comments Do not use any println in comments for Java, otherwise test case fail due to stupid judging system.
+ 0 comments C++
int main() { string S; getline(cin, S); int t; try{ t= stoi(S.c_str()); cout << t; } catch (const exception& e){ // cout << e.what() << endl; cout<<"Bad String"; } return 0; }
Load more conversations
Sort 909 Discussions, By:
Please Login in order to post a comment