Java placeholder application and java placeholder Application

Source: Internet
Author: User

Java placeholder application and java placeholder Application

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

The format () method of the String class is used to create formatted strings and connect multiple String objects. If you are familiar with C, you should remember the sprintf () method of C. The two have similarities. The format () method has two reloads.

Format (String format, Object... args) The new String uses the local language environment to create the String format and parameters to generate the formatted new String.

Format (Locale locale, String format, Object... args) uses the specified language environment to create String formats and parameters to generate formatted strings.

Display different Conversion characters to convert different data types to strings ,.

Conversion character

Description

Example

% S

String type

"Mingrisoft"

% C

Character Type

'M'

% B

Boolean Type

True

% D

INTEGER (decimal)

99

% X

Integer type (hexadecimal)

FF

% O

Integer type (octal)

77

% F

Floating Point Type

99.99

%

Hexadecimal floating point type

FF.35AE

% E

Exponential type

9.38e + 5

% G

General floating point type (shorter of the f and e types)

 

% H

Hash code

 

%

Percentage type

%

% N

Line Break

 

% Tx

Date and Time type (x represents different date and time Conversion characters

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 "," Wang Li "," Wang Zhang "); System. out. println (str); System. out. printf ("uppercase letter a: % c % n", 'A'); System. out. printf ("3> 7: % B % n", 3> 7); System. out. printf ("half of 100 is: % d % n", 100/2); System. out. printf ("The hexadecimal number of 100 is: % x % n", 100); System. out. printf ("the octal number of 100 is: % o % n", 100); System. out. printf ("50 yuan book 8.5 discount: % f yuan % n", 50*0.85); System. out. printf ("The hexadecimal number of the above price is: % a % n", 50*0.85); System. out. printf ("the above price index: % e % n", 50*0.85); System. out. printf ("the result length of the above price index and floating point number is shorter: % g % n", 50*0.85); System. out. printf ("the discount above is % d % n", 85); System. out. printf ("the hash code for letter A is: % h % n", 'A ');}

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.