A string that represents a numeric value

Source: Internet
Author: User

Title description Implement a function to determine whether a string represents a numeric value (including integers and decimals). For example, the string "+100", "5e2", "123", "3.1416" and " -1E-16" all represent numeric values. But "12e", "1a3.14", "1.2.3", "+-5" and "12e+4.3" are not.  public class Solution {   private int inx;   public boolean isnumeric (char[] str) {        if (str = = NULL | | str.length = = 0) {            return false;       }        inx = 0;       boolean flag = Scaninteger (str);        //Judging        if (Inx < str.length && Str[inx] = = '. ') {           inx = Inx + 1;            flag = Scanuinteger (str) | | Flag     //explain a, see below code &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;   //Judgment Index part        if (Inx < str.length && (str[inx]== ' e ' | | str[inx]== ' E ')) {           inx = Inx + 1;            flag = Flag && scaninteger (str);        }       return flag && Inx = = str.length;    }    //determines whether the integer    public boolean scaninteger (char[] str) {        if (Inx < Str.length && (Str[inx] = = ' + ' | | str[inx] = = '-')) {            inx = Inx + 1;       }        return Scanuinteger (str);    }    // Determines whether the unsigned integer    public boolean scanuinteger (char[] str) {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; int inx1 = Inx;       while (Inx < str.length && Str[inx] >= ' 0 ' && Str[inx] <= ' 9 ') {          inx = Inx + 1;        }       return inx > inx1;    }}a. The reason why the use of | |, but not the use of &&. Decimals can have no integer part, such as. 123 equals 0.123, there can be no number after the decimal point, such as 233. equals 233.0; Of course, there can be numbers before and after the decimal point, such as 1.123;

A string that represents a numeric value

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.