char转int,int转char

char转int

1)

char ch = '9';
if (Character.isDigit(ch)){  // 判断是否是数字
    int num = Integer.parseInt(String.valueOf(ch));
    System.out.println(num);
}  

2)

char ch = '9';
if (Character.isDigit(ch)){  // 判断是否是数字
    int num = (int)ch - (int)('0');
    System.out.println(num);
}

int转char

int number = 9;
char cNumber= (char) (number+'0');
System.out.println("Number "+number+" to char is:"+cNumber);

 

 

posted @ 2019-09-02 10:41  悦风旗下  阅读(27521)  评论(0编辑  收藏  举报