【问题标题】:Java 2D Array return not correct, why? [duplicate]Java 2D 数组返回不正确,为什么? [复制]
【发布时间】:2017-09-05 20:55:39
【问题描述】:

为什么我会返回 -1?确定名称在stadiumSeats[i][j]

`public int searchForGuest(final String name){       
    for(int i=0; i<stadiumSeats.length; i++){
        for(int j=0; j<stadiumSeats.length; j++){
            if(stadiumSeats[i][j] == name){
                return i;
            }
        }
    }
    return -1;
}`

【问题讨论】:

    标签: java if-statement multidimensional-array return iteration


    【解决方案1】:

    比较字符串,使用equal函数

    【讨论】:

      猜你喜欢
      • 2013-12-04
      • 2021-12-20
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多