System.out.format
时间: 2023-11-11 12:05:49 浏览: 35
System.out.format is a method in the Java programming language that allows developers to print formatted output to the console or other output streams. It is similar to System.out.println, but allows for more control over the formatting of the output.
The method takes a string as its first argument, which can contain format specifiers such as "%d" for integers, "%f" for floating-point numbers, and "%s" for strings. These specifiers are replaced with the corresponding values passed as additional arguments to the method.
Here's an example:
```
int age = 30;
double salary = 50000.50;
String name = "John Doe";
System.out.format("Name: %s%nAge: %d%nSalary: $%.2f", name, age, salary);
```
This would output:
```
Name: John Doe
Age: 30
Salary: $50000.50
```