我可能只是很累。但不管我嘗試過的代碼總是執行。 如何獲取下面的代碼,只有在字符串包含字符時才執行?JOptionPane.showInputDialog問題
String input = JOptionPane.showInputDialog(this, "Enter your budget!", "Set Budget", 1);
//If the input isnt empty
System.out.println(input);
if(!"".equals(input) || input != null){
try{
budgetValue = Double.parseDouble(input);
budgetIn.setText(String.format("$%1$,.2f", budgetValue));
setDifference();
}
catch(Exception ex){
JOptionPane.showMessageDialog(this, "Unable to set budget!\n" +
"Please enter a usable value!", "Sorry!", 0);
}
}
您應該在AND條件中使用AND(&&)運算符而不是OR(||)。 – ntalbs
還:那system.out.println()是我看到的字符串確實是null –
哦。謝謝..我一直在用Java編程一段時間,從來沒有遇到過這個問題|| ..你能解釋爲什麼請嗎? –