/**
* 1. 字符转数值(先转换为string再转换为int)
* 将字符9转换为数字9,再加3
*/
char char1 = '9';
String str1 = String.valueOf(char1);
System.out.println(Integer.valueOf(str1)+3);
/**
* 2. 字符转字符串
* 将字符9转为字符串并拼接字符串哈哈哈
*/
char char2 = '9';
String str2 = String.valueOf(char2);
System.out.println(str2+"哈哈哈");
/**
* 3. 字符串转字符
*/
String str3 = "abs";
char[] char3 = str3.toCharArray();
System.out.println(char3);
/**
* 4. 字符串转数值
* 将字符串123转为数值并加2
*/
String str4 = "123";
int num4 = Integer.valueOf(str4);
System.out.println(num4+2);
/**
* 5. 数值转字符
*/
int num5 = 123;
String str5=String.valueOf(num5);
char[] char5 = str5.toCharArray();
System.out.println(char5);
/**
* 6. 数值转字符串
*/
int num6 = 456;
String str6 = String.valueOf(num6);
System.out.println("456转为字符串是:"+str6);
/**
* 7.字符转ASCII码
*/
char char7 = '9';
int num7 =(int)char7;
System.out.println(num7);
/**
* 8.ASCII码转为字符
*/
int num8 = 97;
char char8 = (char) num8;
System.out.println(char8);
java字符、字符串、数值、ASCII码的转换
于 2021-12-29 17:38:38 首次发布