【发布时间】:2021-02-28 23:13:38
【问题描述】:
这是不循环的部分
import javax.swing.JOptionPane; // needed to use dialog boxs
public class PalindromeDetector
{// begin class
public static void main(String[] args)
{//begin main
String userWord, continueLoop = " ";
int numString;
JOptionPane.showMessageDialog(null, "This program will ask the user for a string and check to see if it is a palindrome.");
do
{//begin do while loop
userWord = JOptionPane.showInputDialog("enter a string.");
if(PalORNot(userWord))
JOptionPane.showMessageDialog(null, userWord + " is a palinedrome.");
else
JOptionPane.showMessageDialog(null, userWord + " is not a palinedrome.");
continueLoop = JOptionPane.showInputDialog("Would like to try again? enter yes to try again or quit to exit.");
} while (continueLoop == "Yes" || coninueLoop == "yes"); //end do while loop
【问题讨论】:
-
第二次检查中的
coninueLoop是不是拼写错误?顺便说一句,最好将用户答案转换为大写,然后仅检查 YES。 -
哦,我复制错了。即使 continueLoop 变量拼写相同,它仍然不会循环。
-
检查这个。你应该使用
continueLoop.equals("Yes")而不是continueLoop == "Yes":stackoverflow.com/q/513832/260313 -
是的,我写了,现在可以了,谢谢。
标签: loops while-loop