在if语句中使用数组字符串

时间:2013-11-27 15:13:29

标签: java arrays if-statement int

我正在尝试根据数组中是否存在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语句在这里引起了我的注意,我在这里是关闭还是完全不合适?

2 个答案:

答案 0 :(得分:5)

if (department="London")

应该是

if ("London".equals(department))

if(department ="Dublin")语句

也是如此

更多信息:

答案 1 :(得分:0)

您正在使用赋值运算符=而不是等于==