说我要回这样的事: “标题BOOKTITLE,作者BOOKAUTHOR:$ 成本”格式化字符串中使用Java返回的String.Format(...)
鸡舍粗体是变量。 我无法弄清楚如何返回此使用的String.Format( “%S ..,等等等等”)
说我要回这样的事: “标题BOOKTITLE,作者BOOKAUTHOR:$ 成本”格式化字符串中使用Java返回的String.Format(...)
鸡舍粗体是变量。 我无法弄清楚如何返回此使用的String.Format( “%S ..,等等等等”)
String fs;
fs = String.format("Title %t, Author %a: $%c", bookTitle, bookAuthor, cost);
System.out.println(fs);
http://download.oracle.com/javase/tutorial/java/data/strings.html
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);
2串和精度2
浮法String.format("Title %s, Author %s: $%f.2", bookTitle, bookAuthor, cost);