Day 16 : Exceptions
Solution In Java 8:
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.println(i);
}catch(NumberFormatException nfe){
System.out.println("Bad String");
}
}
}
Solution In Python 3:
#!/bin/python3
import sys
try:
print(int(input()))
except ValueError:
print("Bad String")
0 comments:
Post a Comment