day02--数据类型转换_字符的转换
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package com.inmind;
|
||||||
|
/*
|
||||||
|
数据转换--字符数据
|
||||||
|
字符在数学运算中,是遵循ASCII码表,将对应码表中的字符对应的十进制的值参与运算
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class Demo05 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//定义一个字符变量(2个字节)
|
||||||
|
char c = 'a';
|
||||||
|
//定义一个整数int(4个字节)
|
||||||
|
int i = 10;
|
||||||
|
int sum = i + c;//此时发生了自动类型转换,char->int
|
||||||
|
System.out.println(sum);//107
|
||||||
|
|
||||||
|
//int强转字符char,如何操作的??
|
||||||
|
int i1 = 111;
|
||||||
|
char c1 = (char) i1;
|
||||||
|
System.out.println(c1);//o 遵循ASCII码表,转为对应的字符
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user