我得到了这个代码:
System.out.println("Enter the brand and cash value");
String brand = keyboard.nextLine();
long cash = keyboard.nextDouble();
String buffer = keyboard.nextLine();
但即使我输入了我要比较的确切字符串值,它也无法识别它们是相同的。奇怪的是,当我输入这个时:
compare[0] = new Car ("BMW", 12.00);
而不是这个:
compare[0] = new Car (brand, 12.00);
有用
我也使用等于:
public boolean equals(Car other)
{
if (other == null)
{
return false;
}
if(this.brand == other.brand && this.cash == other.cash)
{
return true;
}
else
{
return false;
}
}