我有一个关于使用的问题Boolean.valueOf(String)
。true
在我的代码中,用户将通过输入或来回答问题false
。然后应该将 String 转换为boolean
.
public String setCorrespondingAuthor ()
{
String respons = "true";
do
{
System.out.print("Is s/he the corresponding author? (true/false)");
respons = sc.next();
sc.nextLine();
} while (!respons.equalsIgnoreCase("true")
&& !respons.equalsIgnoreCase("false"));
boolean flag = Boolean.valueOf(respons);
if (!flag)
{
return "not the corresponding author";
}
return "the corresponding author";
}
现在,它工作正常。问题是在输出中,它在处理之前提示了两次问题。