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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 16: Exceptions - String to Integer
  5. Discussions

Day 16: Exceptions - String to Integer

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 909 Discussions, By:

recency

Please Login in order to post a comment

  • jaik1151
    3 days ago+ 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|
    Permalink
  • Abhinav_Ronge
    2 weeks ago+ 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")
    
    0|
    Permalink
  • cafavila
    2 weeks ago+ 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|
    Permalink
  • haoranlu07
    2 weeks ago+ 0 comments

    Do not use any println in comments for Java, otherwise test case fail due to stupid judging system.

    0|
    Permalink
  • hanzg2020
    1 month ago+ 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;
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy