【发布时间】:2014-12-08 17:13:30
【问题描述】:
我正在尝试使用以下参数创建一个名为 loopquery 的方法:
/** create a method named loopquery()
* - that returns a boolean value
* - accepts no arguments
* - content:
* - declaration of a boolean variable initialized to false
* - an InputDialog that requests if you want to loopagain (y,n)and assigns the value to a string variable
* - converts the String variable to upper case
* - changes the value of the boolean variable to true if the string variable has a value of "Y"
* - returns the value of the boolean variable
*/
以下是对它的影响,但我认为我错过了很多。有没有人可以帮助我满足上述所有要求?这是我的呕吐代码
private static void loopquery() {
String loopquery;
boolean loopagain = true;
loopquery = JOptionPane.showInputDialog(null, "Another table (y.n)",
"Again?", JOptionPane.QUESTION_MESSAGE);
loopquery = loopquery.toUpperCase();
}
【问题讨论】:
-
简而言之,虽然这不是有效的代码:
if (loopquery == "Y") { loopagain = true } else { loopagain = false} -
String s="no"; if(boolean) s="yes";,如标题所示。 -
that returns a boolean value你的方法定义应该是boolean那么。 -
根据 java bean 命名约定,你应该调用你的方法“isLoopquery()”
-
如果您遵循@MarcB 的代码,请确保使用
if (loopquery.equals("Y"))