我是新來這個網站,以及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