Java中基本类型
2016-04-16 13:55
531 查看
1.Java中的基本类型
求取代码如下:
2.类型转换
a)自动转换:
程序执行过程中悄然进行的转换,不需要用户提前声明,一般是从位数低的类型转换为位数高的类型;
优先级如下;(byte,short,char)->int->long->float->double
b)强制类型转换
在代码中声明,要在需要转换的类型前加上“()”,括号内填写需要转换成的类型。
测试代码如下:
参考链接:
http://www.cnblogs.com/doit8791/archive/2012/05/25/2517448.html
求取代码如下:
System.out.println(Byte.SIZE); System.out.println(Character.SIZE); System.out.println(Short.SIZE); System.out.println(Integer.SIZE); System.out.println(Long.SIZE); System.out.println(Float.SIZE); System.out.println(Double.SIZE); System.out.println(Byte.MAX_VALUE);
2.类型转换
a)自动转换:
程序执行过程中悄然进行的转换,不需要用户提前声明,一般是从位数低的类型转换为位数高的类型;
优先级如下;(byte,short,char)->int->long->float->double
b)强制类型转换
在代码中声明,要在需要转换的类型前加上“()”,括号内填写需要转换成的类型。
测试代码如下:
class Demo{ //char to int :auto exchange int fun1(){ char i='a'; return i; } //byte to short :auto exchange short fun2(){ byte i=1; return i; } //short to byte :cast exchange byte fun3(){ short i=1; return (byte) i; } //char to byte :cast exchange byte fun4(){ char i='a'; return (byte) i; } //byte to char :cast exchange char fun5() { byte i=1; return (char) i; } //char to short :cast exchange short fun6(){ char i='a'; return (short) i; } //short to char :cast exchange char fun7() { short i=1; return (char) i; } //int to float :auto exchange float fun8(){ int i=1; return 1; } //long to float :auto exchange float fun9(){ long i=1; return i; } //double to float :cast exchange float fun10(){ double i=1; return (float) i; } }
参考链接:
http://www.cnblogs.com/doit8791/archive/2012/05/25/2517448.html
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树