Java string string complement 0 or space

Source: Internet
Author: User

Original: http://www.open-open.com/code/view/1471488086408

 PackageCn.com.songjy;ImportJava.text.NumberFormat;//0 in Java to the left of the number Public classNumberformattest { Public Static voidMain (string[] args) {//data to be tested        inti = 1; //get an example of a NumberFormatNumberFormat NF =numberformat.getinstance (); //set whether to use groupingNf.setgroupingused (false); //To set the maximum number of integer digitsNf.setmaximumintegerdigits (4); //set the minimum number of integer digitsNf.setminimumintegerdigits (4); //Output Test StatementSystem.out.println (Nf.format (i)); }}/*** Java Digital to string in front of auto-complement 0 implementation. *     */   Public classTeststringformat { Public Static voidMain (string[] args) {intYounumber = 1; //0 on behalf of the preceding supplement 0//4 for length 4//d for parameter is positive typeString str = String.Format ("%04d", Younumber); System.out.println (str); //0001  }   }  //serial number plus 1 returns, serial number length is 4    Private Static FinalString str_format = "0000";  Public Staticstring haoaddone_2 (String Liushuihao) {Integer Inthao=Integer.parseint (Liushuihao); Inthao++; DecimalFormat DF=NewDecimalFormat (Str_format); returnDf.format (Inthao); }

Java string string complement 0 or space

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.