stringToInt

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");
	 }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章