Tag: format specifiers

console.readLine()和console.format():格式说明符引用的参数是什么意思?

这个问题在这里有一个后续问题。 按照本教程并编译给定的RegexTestHarness,分别在console.readLine(String)和console.Format(String)上给出以下错误: 参数类型Console中的方法readLine()不适用于参数(String) 参数类型Console中的方法格式(String,Object [])不适用于参数(String,String,int,int) 根据文档 ,有两个论点: public String readLine(String fmt, Object… args ) public Console format(String fmt, Object… args ) 这两种方法的Object类型的第二个参数是: args – 格式字符串中格式说明符引用的参数。 如果参数多于格式说明符,则忽略额外参数。 参数的数量是可变的,可以为零。 参数的最大数量受定义的Java数组的最大维数限制。 所以我相信在教程发布后它发生了变化。 题:- 什么是格式说明符引用的参数? 首先我认为它是格式说明符本身,但后来我也在Matcher matcher = pattern.matcher(console.readLine(“Enter input string to search: “));上收到错误Matcher matcher = pattern.matcher(console.readLine(“Enter input string to search: “)); 声明。 import java.io.Console; import java.util.regex.Pattern; import java.util.regex.Matcher; […]