import java.util.regex.*;
public class Test1 {
public static void main(String[] args) {
new Test1().stringToInt("-1234567890123");
}
public static void stringToInt(String str)
{
String reg="[+-]?\\d+";
Pattern p=Pattern.compile(reg);
Matcher m=p.matcher(str);
if(m.matches())
{
if((-2^31)<Long.parseLong(str)&&Long.parseLong(str)<(2^31-1))
{
System.out.println(Integer.parseInt(str));
}
else
{
System.out.println("beyond the border of int");
}
}
else
System.out.println("format error");
}
}
stringToInt
最新推荐文章于 2023-01-05 15:01:00 发布