ajsie
ajsie

Reputation: 79776

what does the % % mean in java?

Im a PHP-programmer and wonder what this line means.

System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x))

what does %.3f, %.3f%n and the comma x means?

Upvotes: 3

Views: 13495

Answers (6)

user85421
user85421

Reputation: 29700

and, to be complete, the %n represents the platform specific line separator in the printf...

Upvotes: 1

Malax
Malax

Reputation: 9614

PHP has a similar function: http://php.net/printf The Documentation of the Java version can be found here: http://java.sun.com/javase/6/docs/api/java/util/Formatter.html

Upvotes: 2

Doug Porter
Doug Porter

Reputation: 7897

It is similar to C's printf:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax

Upvotes: 7

James
James

Reputation: 25543

This is standard printf formatting. The % stands for 'put an argument here', and the various dots, numbers and letters after the % specify the type of argument.

Upvotes: 1

bmargulies
bmargulies

Reputation: 100133

%.3f means the same thing in Java as in C/C++. It means a floating point number with three digits after the decimal point.

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 882028

The % character is a format specifier which controls how the corresponding variables are formatted.

In this particular case, the two argumnents x and Math.exp(x) are formatted as floats with three fractional digits.

You should of course already know this, even as a PHP coder, since PHP itself appears to have printf and the format specifiers are listed here.

Upvotes: 1

Related Questions