//P41 将65~71显示转换(强制转换)为char型并输出 2020-03-12 00:38:59
public class Bdb_IntToChar {
public static void main(String[] args) {
//声明int型变量,并赋值,显示转换(强制转换)
char ch1 =(char) 65;
char ch2 =(char) 66;
char ch3 =(char) 67;
char ch4 =(char) 68;
char ch5 =(char) 69;
char ch6 =(char) 70;
char ch7 =(char) 71;
System.out.println("int型数值65显式转换(强制转换)成char类型后的值为:" + ch1);
System.out.println("int型数值66显式转换(强制转换)成char类型后的值为:" + ch2);
System.out.println("int型数值67显式转换(强制转换)成char类型后的值为:" + ch3);
System.out.println("int型数值68显式转换(强制转换)成char类型后的值为:" + ch4);
System.out.println("int型数值69显式转换(强制转换)成char类型后的值为:" + ch5);
System.out.println("int型数值70显式转换(强制转换)成char类型后的值为:" + ch6);
System.out.println("int型数值71显式转换(强制转换)成char类型后的值为:" + ch7);
}
}
/* 光盘\Try\02\09
public class IntToChar {
public static void main(String[] args) {
int i_a = 65;
int i_b = 66;
int i_c = 67;
int i_d = 68;
int i_e = 69;
int i_f = 70;
int i_g = 71;
System.out.println("65转换为char型的结果为" + (char)i_a);
System.out.println("66转换为char型的结果为" + (char)i_b);
System.out.println("67转换为char型的结果为" + (char)i_c);
System.out.println("68转换为char型的结果为" + (char)i_d);
System.out.println("69转换为char型的结果为" + (char)i_e);
System.out.println("70转换为char型的结果为" + (char)i_f);
System.out.println("71转换为char型的结果为" + (char)i_g);
}
}
*/
学习笔记_强制转换
最新推荐文章于 2024-05-04 20:29:53 发布