亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
string.format usage:
Two overloading methods of String.format() string regular type formatting
The last chestnut used the formatting of character types and integer types. Now I will give examples of commonly used types
Home Java JavaBase What is the usage of String.format?

What is the usage of String.format?

Oct 27, 2020 am 11:30 AM

string.format Usage: 1. Use the local language environment for the new string, formulate the string format and parameters to generate a formatted new string; 2. Use the specified language environment, formulate the string format and parameter generation Formatted string.

What is the usage of String.format?

string.format usage:

Two overloading methods of String.format() string regular type formatting

  • format(String format, Object… args) The new string uses the local language environment, specifies the string format and parameters to generate a formatted new string.
  • format(Locale locale, String format, Object… args) Use the specified locale, specify the string format and parameters to generate a formatted string.

The last chestnut used the formatting of character types and integer types. Now I will give examples of commonly used types

##%sString type"Like Please bookmark"##%c%b##%dInteger type (decimal)88%xInteger type (hexadecimal) FFInteger type (octal )##%fFloating point type8.888% aHexadecimal floating point typeFF.35AE9.38 e 5No examples (basically not used)No example (basically not used)% (% special characters %% can display %)##%nLine breakNo examples (basically not used)%txDate and time types (x represents different date and time conversion characters)No examples (basically not used)
String?str=null;??
????str=String.format("Hi,%s",?"小超");??
????System.out.println(str);??
????str=String.format("Hi,%s?%s?%s",?"小超","是個","大帥哥");????????????
????System.out.println(str);???????????????????????????
????System.out.printf("字母c的大寫是:%c?%n",?'C');??
????System.out.printf("布爾結(jié)果是:%b?%n",?"小超".equal("帥哥"));??
????System.out.printf("100的一半是:%d?%n",?100/2);??
????System.out.printf("100的16進(jìn)制數(shù)是:%x?%n",?100);??
????System.out.printf("100的8進(jìn)制數(shù)是:%o?%n",?100);??
????System.out.printf("50元的書打8.5折扣是:%f?元%n",?50*0.85);??
????System.out.printf("上面價格的16進(jìn)制數(shù)是:%a?%n",?50*0.85);??
????System.out.printf("上面價格的指數(shù)表示:%e?%n",?50*0.85);??
????System.out.printf("上面價格的指數(shù)和浮點(diǎn)數(shù)結(jié)果的長度較短的是:%g?%n",?50*0.85);??
????System.out.printf("上面的折扣是%d%%?%n",?85);??
????System.out.printf("字母A的散列碼是:%h?%n",?'A');
Hi,小超?
Hi,小超?是個?大帥哥??
字母c的大寫是:C???
布爾的結(jié)果是:false???100的一半是:50???100的16進(jìn)制數(shù)是:64???100的8進(jìn)制數(shù)是:144???50元的書打8.5折扣是:42.500000?元??
上面價格的16進(jìn)制數(shù)是:0x1.54p5???
上面價格的指數(shù)表示:4.250000e+01???上面價格的指數(shù)和浮點(diǎn)數(shù)結(jié)果的長度較短的是:42.5000???上面的折扣是85%???字母A的散列碼是:41
Match conversion characters and implement advanced functions. In the first example, the $
Conversion symbols Detailed description Example
Character type 'm'
Boolean type true
##%o
77
##%e Exponential type
%g General floating point type (the shorter of f and e types)
%h Hash code
%% Percent type
For the convenience of understanding, let’s give an example Output results

flag

ExplanationExampleAdd a sign to a positive or negative number(“% d”,15)(“d”, 99)("% 4d", 99)##,Use "," to group numbers (commonly used to display the amount)("%,f", 9999.99)9,999.990000(Use brackets to include negative numbers(“%(f”, -99.99) (99.990000)#If it is a floating point number, include the decimal point, if it is hexadecimal or octal, add 0x or 0 (“%#x”, 99)(“%#o”, 99)0x63 014399.450000 and 99.45First one In the example, it is mentioned that %tx c
Result
15 0 Add 0 in front of the number (commonly used for encryption)
0099 Spaces Adds the specified number of spaces before the integer
99
##< Format the previous one The parameters described by the conversion operator ("%f and %<3.2f", 99.45)
d,% 2$s”, 99,”abc”) 99,abc

Includes full date and time information

Saturday October 27 14:21:20 CST 2007F"Year-Month-Day" format2007-10-27D"Month/Day/Year" format10/27/07r"HH:MM:SS PM" format ( 12-hour format)02:25:51 PMT"HH:MM:SS" format (24-hour format)14:28:16R"HH:MM" format (24-hour format)14:28Let’s give an example to facilitate understandingOutput resultsRelated learning recommendations:
Date?date=new?Date();??????????????????????????????????
????//c的使用??
????System.out.printf("全部日期和時間信息:%tc%n",date);??????????
????//f的使用??
????System.out.printf("年-月-日格式:%tF%n",date);??
????//d的使用??
????System.out.printf("月/日/年格式:%tD%n",date);??
????//r的使用??
????System.out.printf("HH:MM:SS?PM格式(12時制):%tr%n",date);??
????//t的使用??
????System.out.printf("HH:MM:SS格式(24時制):%tT%n",date);??
????//R的使用??
????System.out.printf("HH:MM格式(24時制):%tR",date);
全部日期和時間信息:星期三?九月?21?22:43:36?CST?2016??年-月-日格式:2016-09-21月/日/年格式:16/10/21??HH:MM:SS?PM格式(12時制):10:43:36?下午??
HH:MM:SS格式(24時制):22:43:36??HH:MM格式(24時制):22:43
java basic tutorial

The above is the detailed content of What is the usage of String.format?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72