我是新来这个网站,以及Java。条件内条件java
任何人都可以帮助我找出为什么即使没有红点,程序的某些部分仍然无法工作?
我把注释使用/ /行不工作。
import javax.swing.JOptionPane;
public class ChatterBot {
public static void main(String[] args) {
// TODO Auto-generated method stub
String firstName, work, sex = null;
int age;
firstName = JOptionPane.showInputDialog("Hello, my name is Chatterbox. What is your name?");
if (firstName.toLowerCase().contains("name".toLowerCase())) {
JOptionPane.showMessageDialog(null, "Welcome " + firstName.substring(firstName.lastIndexOf(" ") + 1) + "!");
sex = JOptionPane.showInputDialog(null, "Is " + firstName.substring(firstName.lastIndexOf(" ") + 1)
+ " a guy name or a woman name? (type stop to end conversation)");
} else {
JOptionPane.showMessageDialog(null, "Welcome " + firstName + "!");
sex = JOptionPane.showInputDialog(null,
"Is " + firstName + " a guy name or a woman name (type stop to end conversation)");
}
while (true)
if (sex.toLowerCase().contains("guy".toLowerCase())) {
JOptionPane.showMessageDialog(null, "Welcome friend");
work = JOptionPane
.showInputDialog("Would you like to talk about work or do you want to hear a cool story?");
if (work.toLowerCase().contains("work".toLowerCase())) {
JOptionPane.showMessageDialog(null, "Interesting");
break;
} else if (work.toLowerCase().contains("story".toLowerCase())) {
JOptionPane.showMessageDialog(null, "hola");
break;
} else if (sex.toLowerCase().contains("woman".toLowerCase())) {
//when I type woman nothing happens but the else if below for "stop" works.
age = Integer.parseInt(JOptionPane.showInputDialog(null, "How old are you?"));
if (age >= 18 && age <= 40) {
JOptionPane.showMessageDialog(null, "Dayummm");
} else if (age > 40) {
JOptionPane.showMessageDialog(null, "I don't like no cougar!");
} else {
JOptionPane.showMessageDialog(null, "I ain't no pedo. Bye!");
}
}
break;
} else if (sex.toLowerCase().contains("stop".toLowerCase())) {
JOptionPane.showMessageDialog(null, "Have a nice day.");
break;
} else {
JOptionPane.showMessageDialog(null, "Goodbye");
break;
}
}
调试器可以帮助您 – Jens
抱歉,这不是一个“我们调试程序为您”的服务。而且你知道什么有帮助:当加入一个*新的地方时,你首先了解那个地方的规则,而不是盲目地倾销内容。从这个意义上说:请A)删除这个“问题”B)阅读[帮助]并学习如何问一个更好的问题;-) – GhostCat
欢迎来到堆栈溢出!寻求调试帮助的问题(“为什么这个代码不工作?”)必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无益。请参阅:如何创建[mcve]。使用“编辑”链接来改善你的*问题* - 不要通过评论添加更多信息。谢谢! – GhostCat