我可能只是很累。但不管我尝试过的代码总是执行。 如何获取下面的代码,只有在字符串包含字符时才执行?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编程一段时间,从来没有遇到过这个问题|| ..你能解释为什么请吗? –