一、字符转换为ASCII码:
int i=(int)'1';
二、ASCII码转换为字符:
char ch =(char)40;
三、十六进制码转换为字符:
char charValue = (char)'\u0040';
package week3;public class check_point4_8 {public static void main(String[] args) {System.out.println("一、字符转换为ASCII码:");int i=(int)'1';System.out.println("1的ASCII码为"+i);i=(int)'A';System.out.println("A的ASCII码为"+i);i=(int)'B';System.out.println("B的ASCII码为"+i);i=(int)'a';System.out.println("a的ASCII码为"+i);i=(int)'b';System.out.println("b的ASCII码为"+i);System.out.println("二、ASCII码转换为字符:");char ch =(char)40;System.out.println("十进制码为40的字符是"+ch);ch =(char)59;System.out.println("十进制码为59的字符是"+ch);ch =(char)79;System.out.println("十进制码为79的字符是"+ch);ch =(char)85;System.out.println("十进制码为85的字符是"+ch);ch =(char)90;System.out.println("十进制码为90的字符是"+ch);System.out.println("三、十六进制码转换为字符:");char charValue = (char)'\u0040';System.out.println("40的字符值是 " + charValue);charValue = (char)'\u0059';System.out.println("59的字符值是 " + charValue);charValue = (char)'\u0071';System.out.println("40的字符值是 " + charValue);charValue = (char)'\u0072';System.out.println("72的字符值是 " + charValue);charValue = (char)'\u007A';System.out.println("7A的字符值是 " + charValue);}
}
运行结果: