Day 16: Exceptions - String to Integer

  • + 0 comments

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        String S = bufferedReader.readLine();
        try
        {
            System.out.println(Integer.parseInt(S));
        }
        catch(Exception ex)
        {
            System.out.println("Bad String");
        }
        bufferedReader.close();
    }
    

    }