当我将 char 转换为 int 并分配给单元格对象的不同变量时,
但一个分配为 0 的值被分配为 ascii 值。
class Cell {
public Cell() {}
public Cell(int row, int col) {
this.row = row;
this.col = col;
}
public int row;
public int col;
}
Cell makeCell(String str) {
char[] ch = str.toCharArray();
Cell cell = new Cell();
cell.row = ch[1] - 1; ** <--- cell.row assigned 0**
cell.col = ch[0] - 'A'; ** <--- cell.col assigned 48 but why?**
return cell;
}
public static void main(String arg[]){
Cell cell = makeCell("A1");
}
慕侠2389804
慕容森
侃侃无极
相关分类