Java中怎么把int型的数字转换成char型的数字?

如题所述

第1个回答  推荐于2019-11-16
public class Int2CharDemo { public static void main(String[] args) { // 将int类型数字8转换为char类型数字8
int num1 = 8;
char ch1 = (char) (num1 + 48);
System.out.println("ch1 = " + ch1); // 将char类型数字8转换为int类型数字8
// 方法一:
Character ch2 = '8'; // char是基本数据类型,Character是其包装类型。
int num2 = Integer.parseInt(ch2.toString());
System.out.println("num2 = " + num2);
// 方法二:
char ch3 = '8';
int num3 = ch3 - 48;
System.out.println("num3 = " + num3); }
}本回答被网友采纳