我正在尝试根据数组中是否存在String来计算如何向变量添加值。希望我的代码能够更好地解释它:
//calculate bonus
String[] department = {"Dublin","London","London","Dublin","Paris","Paris"};
int [] brokerTotal =(79,35,55,101,63,108};
int[] bonus;
bonus=new int[6];
for(int i = 0;i < department.length; i++) {
if (department ="Dublin") bonusRate=12;
else if (department="London") bonusRate=15;
else bonusRate=10;
bonus[i] = ((brokerTotal[i])/100)*bonusRate;
}
if语句在这里引起了我的注意,我在这里是关闭还是完全不合适?
答案 0 :(得分:5)
if (department="London")
应该是
if ("London".equals(department))
if(department ="Dublin")
语句
更多信息:
答案 1 :(得分:0)
您正在使用赋值运算符=
而不是等于==