Java char is also an int?

前端 未结 7 1809
甜味超标
甜味超标 2020-12-04 02:12

I was trying to get some code done for class:

public int getValue(char value) {
    if (value == \'y\') return this.y;
    else if (value == \'x\') return th         


        
7条回答
  •  臣服心动
    2020-12-04 02:36

    Hope this little example solves your confusion:

    public int getValue(int value) { 
        if (value == 'y') 
            return this.y; 
        else if (value == 'x') 
            return this.x; 
    }
    

    If you pass char as an int like getValue('x'), it would return the value of the int.

提交回复
热议问题