我正在通过 eclipse 检查我的代码,发现我的条件之一无法正常工作!
这是代码:例如,这里的 first = "44"
和 last = "54"
所以第一个 Sub 和最后一个 Sub 是 4、5。
String firstSub = first.substring(0,1);
String firstSub = last.substring(0,1);
System.out.println(firstSub + "..." + lastSub);
if (firstSub.equals(lastSub))
System.out.println("row");
因此,通过打印的输出,我得到第一个 Sub 和最后一个 Sub 不相等,但打印了字符串“row”!
有什么问题吗? 原始代码:
System.out.println(ebteda+ "--" +enteha);
ebtedaSub = ebteda.substring(0,1);
entehaSub = enteha.substring(0,1);
System.out.println(ebtedaSub + "_" + entehaSub);
if(ebtedaSub.equals(entehaSub));
{
System.out.println(ebteda.substring(0,1)+enteha.substring(0,1));
hamsatr(ebteda,enteha);
}
最佳答案
删除 if 后面的 ;
if(ebtedaSub.equals(entehaSub));
{
System.out.println(ebteda.substring(0,1)+enteha.substring(0,1));
hamsatr(ebteda,enteha);
}
应该是这样
if(ebtedaSub.equals(entehaSub))
{
System.out.println(ebteda.substring(0,1)+enteha.substring(0,1));
hamsatr(ebteda,enteha);
}
关于java - 带有条件代码的错误(如果),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21565631/