(1)char只能描述单个字符,若想要描述多个字符则必须使用String。但是需要说明的是String并不是基本数据类型,String是一个引用数据类型,
但是可以套用基本数据类型的形式进行使用。记住,有类型只要与String发生了“+”操作,都变为String类型。
示例:观察转义字符
public class Test {
public static void main(String[] args) {
System.out.println("今天\"张三\"出去玩,去整人");
System.out.println("今天\n\"张三\"出去玩,去整人");
System.out.println("\t\t今天\"张三\"出去玩,去整人");
System.out.println("今天张三出去玩,去整人");
}
}
结果:
今天"张三"出去玩,去整人
今天
"张三"出去玩,去整人
今天"张三"出去玩,去整人
今天张三出去玩,去整人
(2)bool类型
在其他语言中没有提供布尔型的数据,会使用数字描述布尔型,eg:0表示false,非0表示true。但是java没有这样的概念。
(3)字符型
字符型使用char进行表示,而且使用单引号进行表示字符变量的内容,字符型可以与int相互转换。,
public class Test {
public static void main(String[] args) {
char c='A';
int num=c;
System.out.println(num);
}
}
结果:65
总结:范围:大写字母A~Z为65~90 小写字母a~z为97~122 字符数字:'0'~'9':48~57
范例:实现大写字母和小写字母的转换(大写和小写字母之间查了32个长度)
public class Test {
public static void main(String[] args) {
char c='A';
int num=c+32;//字符串变量+int常量=int类型
System.out.println(num);
char x=(char)num;//强制转换为char型
System.out.println(x);
}
}
结果:
97
a
阅读排行
- Java面试题全集(上) (1102927 )
- Wi-Fi 爆重大安全漏洞,Android、iOS、Windows 等所有无线设备都不安全了 (422517 )
- Jquery 使用Ajax获取后台返回的Json数据后,页面处理 (268459 )
- Java面试题全集(中) (236890 )
- 一个非常有用的函数——COALESCE (222876 )
- Java面试题全集(下) (220857 )
- Uncaught SyntaxError: Unexpected token ) (213375 )
- 如何用adb连接android手机?(我的亲自经历)------ 顺便说说unable to connect to 192.168.1.100:5555的原因和解决方法 (210592 )
- 如何利用C/C++逐行读取txt文件中的字符串(可以顺便实现文本文件的复制) (207456 )
- yum提示Another app is currently holding the yum lock; waiting for it to exit... (205660 )