Valid bank money number

Source: Internet
Author: User

I have always been unsure of such questions. I have no idea.

I

1,000,000.22

34,333.999

Define valid (string S, Boolean last, Boolean first)

1. First S. Trim ();

If String = NULL or string. Length = 0 return false;

2. String [] T = S. Spite (',');

Number of groups.

If (T. Length () = 1) valid (T [0], T, T)

Else ()

 

For splite function 1, The last S. Length = 1. Only 1 is left.

 

 

 

 

You need to consider the situation!

The most important thing is to write down all the situations first. Based on the graph. The examiner will be very clear.

 

import java.util.ArrayList;import java.util.List;public class test {    /**     * @param args     */    public static Boolean isNum(String s){        if(s == null || s.length()==0)            return false;        s = s.trim();                //check the ,, situation         String[] t = s.split(",");        int comcount = 0;        for(int i=0;i<t.length;i++){            if(s.charAt(i)==‘,‘)                comcount++;        }        if(t.length!=comcount+1)            return false;                if(t.length==1)            return Valid(t[0], true, true);        else         {            for(int i=0; i< t.length;i++){                if(i==0){                    if(!Valid(t[i], true, true))                        return false;                }                else if(i==(t.length-1)){                    if(!Valid(t[i],false,true))                        return false;                }else{                    if(!Valid(t[i],false,false))                        return false;                }                            }        }        return true;    }//    //effective fractional 100.222222//    public static boolean Valid2(String s){//        if(s.length() == 0)//            return false;//    }//        public static Boolean Valid(String s, boolean f, boolean l){        if(f){                                //+10234  -00234            if(s.length()>0 && (s.charAt(0)==‘-‘ || s.charAt(0)==‘+‘))                s = s.substring(1);            char[] arr = s.toCharArray();            if(arr.length==0)                return false;            int indexDot = s.indexOf(".");            if(indexDot ==-1){                //23     333                if(s.length()>3)                    return false;            }else{                if(indexDot>3)                    return false;                for(int i=0;i<indexDot;i++){                    if(!check(s.charAt(i)))                        return false;                }                if(indexDot==s.length()-1)                    return false;                for(int i=indexDot+1;i<s.length();i++){                    if(!check(s.charAt(i)))                        return false;                }            }                                return true;        }        if(l){            if(s.length()<3)                return false;            for(int i=0;i<3;i++)            {                if(!check(s.charAt(i)))                    return false;            }                if(s.length()>3){                if(s.charAt(3)!=‘.‘)                    return false;                for(int i=4;i<s.length();i++){                    if(!check(s.charAt(i)))                        return false;                }            }            return true;        }        // middle        if(s.length()!=3)                return false;        char[] arr = s.toCharArray();        for(int i=0;i<arr.length;i++){            if(!check(arr[i]))                    return false;        }                return true;    }        static boolean check(char c){        return (‘0‘ <= c && c <= ‘9‘);    }        public static void main(String[] args) {                String[]t = {",,","100,002",",000.3",                "+34444","9999.234324","234234",                "+56.234234","1,000,000,030.21231","-0.3242",                ".+99","1111.6",",999.3"                ,"+1,000,987.23444444444"                };        for(String c:t)        System.out.println(isNum(c));    }}

 

Valid bank money number

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.