Recently in writing a small algorithm, need to deal with decimals, the first thought is to determine whether there is a decimal point in the number of decimal points to the end of several .... It's too much trouble to write a half, because a lot of value to deal with too much trouble ...
I finally wrote this to use, and I feel better.
public static Boolean isNumber1 (String str) {//Judge integral return
str.matches ("^\\d+$$");
}
public static Boolean isNumber2 (String str) {//Judge Decimal, and the difference between the judgment integer and the decimal point (red) return
str.matches ("\\d+\\.\\d+$") after the D;
Public
Static Boolean isNumber3 (String str) {//Judge the start of the decimal point return
str.matches ("\\.\\d+$");
}
public static void Main (string[] args) {
//TODO auto-generated method stub
String ab = "963";
System.out.println ("1" + a.isnumber1 (AB));
System.out.println ("2" + a.isnumber2 (AB));
System.out.println ("3" + A.isnumber3 (AB));
}
Here, make a note for yourself ... I hope I can help someone who needs as much as I do.