Jan*_*cka 2 java string format
说我想要回复这样的东西:"Title bookTitle,Author bookAuthor:$ cost "
粗体是变量.我无法弄清楚如何使用string.format("%s ..,blah blah")返回此内容
String title = "bookTitle";
String author = "bookAuthor";
double cost = 100;
String text = String.format("Title %s, Author %s: $%.2f", title, author, cost);
System.out.println(text); // prints "Title bookTitle, Author bookAuthor: $100.00"
// or System.out.pritnf("Title %s, Author %s: $%.2f", title, author, cost);
Run Code Online (Sandbox Code Playgroud)
2 个字符串和一个精度为 2 的浮点数
String.format("Title %s, Author %s: $%f.2", bookTitle, bookAuthor, cost);
Run Code Online (Sandbox Code Playgroud)