1. How do I output a number to a three-bit comma-delimited format, such as "1,234,467"?
1 Packagecom. Gxjun.problem;2 3 ImportJava.text.DecimalFormat;4 ImportJava.util.Scanner;5 6 7 /*8 * How to output the number to a comma-delimited format of three bits,9 * For example "1,234,467"? Ten * */ One A Public classFloatdirve { - - Public Static voidMain (String args []) { theScanner reader =NewScanner (system.in); - while(Reader.hasnext ()) { - System.out.println (Funcformat (Reader.nextdouble ())); - } + } - /*use a method to handle this format*/ + Public StaticString Funcformat (DoubleDoub) { AString str= "# # #"; at intlen=string.valueof (Doub). Length (); - for(intI=3;i<=len;i+=3){ -Str+= ", # # #"; - } -DecimalFormat DECF =NewDecimalFormat (); - Decf.applypattern (str); in returnDecf.format (Doub); - } to}View Code
Java basic knowledge point (Must know the second)