java中char类型转换成int类型的两种方法

方法一:

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

方法二:

char ch = '9';
if (Character.isDigit(ch)){  // 判断是否是数字
	int num = (int)ch - (int)('0');
	System.out.println(num);
}
posted @ 2018-08-21 11:24  DaleyZou  阅读(65179)  评论(2编辑  收藏  举报