— Scott McNealy, Sun Microsystems Chairman, President and ceo


String.format(“%, d”, 1000000000)



Download 40,57 Mb.
Pdf ko'rish
bet280/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   276   277   278   279   280   281   282   283   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

String.format(“%, d”, 1000000000);
System.out.println(s);
}
}
Formatting a number to use commas
The number to format (we 
want it to have commas).
Now we get commas inserted into the number.
 1,000,000,000
number 
formatting
The formatting instructions for how to format the 
second argument (which in this case is an int value). 
Remember, there are only two arguments to this method 
here—the first comma is INSIDE the String literal, so 
it isn’t separating arguments to the format method.


numbers 
and
statics
you are here
4
295
Formatting deconstructed...
format(“%, d”, 1000000000);
At the most basic level, formatting consists of two main parts 
(there is more, but we’ll start with this to keep it cleaner):
Formatting instructions
1
The argument to be formatted.
2
1
2
Use these instructions... on this argument.
You use special format specifiers that describe how 
the argument should be formatted.
Although there can be more than one argument, we’ll 
start with just one. The argument type can’t be just 
anything... it has to be something that can be formatted 
using the format specifiers in the formatting instructions. 
For example, if your formatting instructions specify a 
floating point number, you can’t pass in a Dog or even a 
String that looks like a floating point number.
What do these instructions actually say?
“Take the second argument to this method, and 
format it as a 
d
ecimal integer and insert 
commas
.”
How do they say that?
On the next page we’ll look in more detail at what the syntax “%, 
d” actually means, but for starters, any time you see the percent 
sign (%) in a format String (which is always the first argument 
to a format() method), think of it as representing a variable, 
and the variable is the other argument to the method. The rest 
of the characters after the percent sign describe the formatting 
instructions for the argument. 
Do this...
to this.
Note: if you already know printf() 
from c/C++, you can probably just 
skim the next few pages. Otherwise, 
read carefully!



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   276   277   278   279   280   281   282   283   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish