Before going to bed at night, get this interesting question and try to play with it:
============================================================================
Rule: "Random floating-point numbers are written according to the RMB reading method"
The total code is as follows:
Packagecom.sxd.test;Importorg.junit.Test;ImportJava.text.DecimalFormat;ImportJava.util.Random;/*** @Author SXD*/ Public classrandomtest {@Test Public voidCreaterandom () {DecimalFormat DF=NewDecimalFormat ("0.00"); Random Random=NewRandom (); DoubleAA = (random.nextdouble ()) *(Random.nextint (Integer.max_value)); System.out.println (Df.format (AA)); System.out.println (DEAL4RMB (Df.format (AA))); } /*** from the decimal point to the dividing line, the forward iterative processing + stitching the corners + some rules *@paramdbnum Random floating-point value *@returnconverted RMB Capitalization value description*/ Privatestring DEAL4RMB (String dbnum) {string SB= ""; Try { intPoint = Dbnum.lastindexof (".")); Char[] Chararr =Dbnum.tochararray (); for(inti = 1; I <= point; i++) {String flag= Getuppercase (chararr[point-i],i); SB= Flag +SB; if("Error". Equals (flag) { return"Conversion Exception"; }} SB=dealstring (SB); SB= sb+ "meta" +getuppercase (chararr[point+1],-1) +getuppercase (chararr[point+2],-2); }Catch(Exception e) {System.out.println (e); return"Conversion Exception"; } returnSB; } /*** Replace Chinese RMB count + partial rule *@parama value *@paramI location *@returnvalue + Position*/ PrivateString Getuppercase (CharAinti) { //the standard value is 0 and the standard position is two digits after one decimal point//Do not make any return operations if(' 0 ' = = a && (i==1 | | i==-1 | | i==-2)){ return""; } //the standard value is 0 and the standard position in the million-bit//returns only million instead of tens of thousands of if(' 0 ' = = a && i==5) { returnMarriott; } //the capital number of Chinese characters in the standard digital conversionString flag = ""; //the standard position corresponds to "angle of top"String Flag2 = ""; Switch(a) { Case' 0 ': flag = "0"; Break; Case' 1 ': flag = "one"; Break; Case' 2 ': flag = "Ii."; Break; Case' 3 ': flag = "three"; Break; Case' 4 ': flag = "the premises"; Break; Case' 5 ': flag = "WU"; Break; Case' 6 ': flag = "land"; Break; Case' 7 ': flag = "QI"; Break; Case' 8 ': flag = "ba"; Break; Case' 9 ': flag = "JIU"; Break; default: Flag = "Error"; } //Standard for zero non-splicing of the standard position "in addition to the million has been handled alone" if(!" Zero. Equals (flag) { Switch(i) { Case-1:flag2 = "angle"; Break; Case-2:flag2 = "min"; Break; Case2: Case6: Case10:flag2 = "Ten"; Break; Case3: Case7: Case11:flag2 = "hundred"; Break; Case4: Case8:flag2 = "thousand"; Break; Case5:flag2 = "million"; Break; Case9:flag2 = "billion"; Break; default: Flag2 = ""; } } /*** This service is incomplete * because the probability of a random number of integers reaching more than 10 digits is very large * therefore processing only a ten to thousands of millions of this situation * if the random number level in 100,000 will still appear one A hundred thousand of thousands of hundreds of * if the random number level in 10 will still appear a few more than 10 points of the situation * * to complete processing, only need to determine the total number of random numbers, and then judge the value of I for the first few special treatment can ~ ~*/ if("One". Equals (flag) && "ten". Equals (Flag2) && i = = 10){ returnFlag2; } //return value + position returnflag+Flag2; } /*** Remove duplicate 0 + partial rule *@paramRmbstr *@return */ Privatestring dealstring (String rmbstr) { while(Rmbstr.indexof ("00") >= 0) {Rmbstr= Rmbstr.replace ("00", "0"); } //determine if the digit is still zero if the zero intercept string can be Char[] arr =Rmbstr.tochararray (); if(' 0 ' = = arr[arr.length-1]) {rmbstr= Rmbstr.substring (0,rmbstr.length ()-1); } returnRmbstr; }}
View Code
Effect Show:
"Java" Java handles random floating-point numbers (two digits after the decimal point) output with an uppercase numeric rule of RMB