Day 16: Exceptions - String to Integer

  • + 0 comments

    for code java public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String S = sc.nextLine(); try{ int num = Integer.parseInt(S);
    System.out.println(num); }catch(Exception e){ System.out.println("Bad String"); }

    }
    

    }