— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet285/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   281   282   283   284   285   286   287   288   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

%,d
out of 
%,.2f
”, 
one

two
);
When you have more than one 
argument, they’re inserted 
using the order in which you 
pass them to the format() 
method.
As you’ll see when we get to date formatting, you might actually want to apply different 
formatting specifiers to the same argument. That’s probably hard to imagine until you 
see how date formatting (as opposed to the number formating we’ve been doing) works. 
Just know that in a minute, you’ll see how to be more specific about which format 
specifiers are applied to which arguments.
The rank is 20,456,654 out of 100,567,890.25
We added commas to both variables, 
and restricted the floating point 
number (the second variable) to two 
decimal places.
Q: 
Um, there’s something REALLY strange going on here. Just how many arguments can I 
pass? I mean, how many overloaded format() methods are IN the String class? So, what happens 
if I want to pass, say, ten different arguments to be formatted for a single output String?
A: 
Good catch. Yes, there is something strange (or at least new and different) going on, and 
no there are not a bunch of overloaded format() methods to take a different number of possible 
arguments. In order to support this new formatting (printf-like) API in Java, the language needed 
another new feature—variable argument lists (called varargs for short). We’ll talk about varargs 
only in the appendix because outside of formatting, you probably won’t use them much in a well-
designed system.
format 
arguments


numbers 
and
statics
you are here
4
301
So much for numbers, what about dates?
Imagine you want a String that looks like this: “Sunday, Nov 28 2004”
Nothing special there, you say? Well, imagine that all you have to start with is a variable 
of type Date—A Java class that can represent a timestamp, and now you want to take that 
object (as opposed to a number) and send it through the formatter.
The main difference between number and date formatting is that date formats use a 
two-character type that starts with “t” (as opposed to the single character “f” or “d”, for 
example). The examples below should give you a good idea of how it works:
String.format(“

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   281   282   283   284   285   286   287   288   ...   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