Java is a simple way to determine the beginning of integers, decimals, and decimal points

Source: Internet
Author: User

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.