Skip to content

Instantly share code, notes, and snippets.

@medmek
Created June 18, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save medmek/b4f91cf4997d0d6a716e55bf643ee86e to your computer and use it in GitHub Desktop.
Save medmek/b4f91cf4997d0d6a716e55bf643ee86e to your computer and use it in GitHub Desktop.
Day 16: Exceptions - String to Integer Hackerrank java7
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String S = in.next();
try{
Integer I = Integer.parseInt(S);
System.out.print(I);
}catch(NumberFormatException e){
System.out.print("Bad String");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment