Java placeholder App

Source: Internet
Author: User
Tags locale string format

(Reprinted from: http://www.cnblogs.com/happyday56/p/3996498.html)

The format () method of the string class is used to create a formatted string and to concatenate multiple string objects. Students familiar with C language should remember the C language of the sprintf () method, the two have similarities. There are two overloaded forms of the format () method.

Format (string format, Object ... args) a new string that uses the local locale to develop a string format and parameters to generate a new formatted string.

Format (locale locale, string format, Object ... args) uses the specified locale to develop string formatting and parameters to generate a formatted string.

Displays different conversion characters that implement different data types to string conversions.

Conversion character

Description

Example

%s

String type

"Mingrisoft"

%c

Character type

' m '

%b

Boolean type

True

%d

Integer type (decimal)

99

%x

Integer type (hex)

Ff

%o

Integer type (octal)

77

%f

Floating-point types

99.99

%a

Hexadecimal floating-point type

Ff.35ae

%e

Index type

9.38e+5

%g

Common floating-point types (shorter in type F and e)

%h

Hash code

%%

Percent type

%n

Line break

%tx

Date and Time type (x represents a different date and time conversion character

Test Cases

    public static void Main (string[] args) {        String str=null;        Str=string.format ("hi,%s", "Wang Li");        System.out.println (str);        Str=string.format ("hi,%s:%s.%s", "Wang Nan", "Li Li", "Wang Zhang");                  System.out.println (str);                                 System.out.printf ("Uppercase of the letter A is:%c%n", ' a ');        System.out.printf ("3>7 results are:%b%n", 3>7);        System.out.printf ("Half of 100 is:%d%n", 100/2);        System.out.printf ("100 of 16 binary numbers are:%x%n", +);        System.out.printf ("100 of 8 binary numbers are:%o%n", +);        System.out.printf ("50 yuan book 8.5 discount is:%f Yuan%n", 50*0.85);        System.out.printf ("16 of the above price is:%a%n", 50*0.85);        System.out.printf ("The index of the above price indicates:%e%n", 50*0.85);        System.out.printf ("The index of the above price and the length of the floating point result is shorter:%g%n", 50*0.85);        System.out.printf ("The above discount is%d%%%n",);        System.out.printf ("The hash code for the letter A is:%h%n", ' a ');    }

Java placeholder App

Related Article

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.