I have a question about the use of Boolean.valueOf(String)
. In my code the user will answer a question by entering either true
or false
. Then the String should be converted to a 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";
}
Right now, it works okay. The problem is that in the output, it prompts the question twice before treat it.