各数据类型之间的关系
来源:互联网 发布:ubuntu 列表显示 编辑:程序博客网 时间:2024/05/21 22:34
当表达式中有类型不匹配时,有下列处理方法:
1.占用较少字节的数据类型会转换成占用较多字节的数据类型。
2.有short和int类型时,则用int类型。
3.字符类型会转换成int类型。
4.int类型转换成float类型。
5.若一个操作数的类型为string,则其他的操作数也会转换成string类型。
6.布尔类型不能转换至其他类型。
程序的3种基本结构的作用:http://zhidao.baidu.com/question/561343838.html
package com.huawei.test;
public class Test1
{
public static void main(String[] args)
{
char cc = '无';
char c= 0;//(字符)
char c1= 1;//(字符)
char c2 = 80;//(ASCII美国字符标准码)A
/*******************************************************/
// c = c+cc; cannot convert from int to char
Short ss = '死';//(ASCII美国字符标准码)1= 49 0=48
Short s = 1;//(ASCII美国字符标准码)1= 49 0=48
Short s1 = 1000; //short 16 2 最大32767
/*******************************************************/
// s= c+s;cannot convert from int to Short
long LL = '死';//(ASCII美国字符标准码)a=97
Long L = 1l;//(ASCII美国字符标准码)a=97
Long L1 = 100000l;//(自动为int最大值就是这个,10位)
Long L2 = 9223372036854775807L; //最大19位 9223372036854775807 (大些开头,就局限L结尾)
/*******************************************************/
L = L+s;
L = L+c;
Byte bb= 'a';
byte b= 1;
byte b1 = 100; //最大127
/*******************************************************/
// c =c2+b1; cannot convert from int to char
float ff = '无';
float f = 1f;
float f1 = 100000;//(自动为int最大值就是这个,10位);
float f2 = 340000000000000000000000099900000000009f; //最大38位
/*******************************************************/
int i = c+s;
i= c+b;
i=ss+bb+cc;
double dd = '无'; //最大38位
double d = 1; //最大38位
double d1 = 2222; //最大38位
double d2 = 22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222.0; //最大38位
String str = String.valueOf(d2);
/*******************************************************/
d = d +c;
d = b+c;
d= i+c;
d= s+c;
d= s+b+c+L+d;
// s = d+c;Type mismatch: cannot convert from double to Short
// s = b+c;pe mismatch: cannot convert from int to Short
// L= b+c;Type mismatch: cannot convert from int to Long
// L = f+c;Type mismatch: cannot convert from float to Long
L = b+c+L;
L = i +L;
f = b+c;
f= s+c;
f = i+c;
f=f+c;
// f = d+c;Type mismatch: cannot convert from double to float
// s=b;Type mismatch: cannot convert from byte to Short
// s= c;Type mismatch: cannot convert from char to Short
// i = f+c;Type mismatch: cannot convert from float to int
// i =d+c;Type mismatch: cannot convert from double to int
// c = s+b;Type mismatch: cannot convert from int to char
// c= s;Type mismatch: cannot convert from Short to char
// c=b;Type mismatch: cannot convert from byte to char
// b=c;Type mismatch: cannot convert from char to byte
// str = s+c+d+b+L+d;Type mismatch: cannot convert from double to String
// L =str;Type mismatch: cannot convert from String to Long
// str = L;Type mismatch: cannot convert from Long to String
System.out.println(" |cc| "+cc+" |c| "+c+" |c1| "+c1+" |c2| "+c2+"----"+(cc+ss)+"--"+(c1+c2)+"--"+(c2+cc));
System.out.println(" |ss| "+ss+" |s| "+s+" |s1| "+s1+"-----"+(s+s1));
System.out.println(" |LL| "+LL+" |L| "+L+" |L1| "+L1+" |L2| "+L2+"----"+(L+L1));
System.out.println(" |bb| "+bb+" |b| "+b+" |b1| "+b1 +"---" +(b+b1));
System.out.println(" |ff| "+ff+" |f| "+f+" |f1| "+f1 +" |f2| "+f2 +"----"+(f+f1));
System.out.println(" |dd| "+dd+" |d| "+d+" |d1| "+d1 +" |d2| "+d2+" |ss.length()| "+str.length()+"---"+(d1+d2)+"------"+(d+d1));
}
}
- 各数据类型之间的关系
- int 与 Integer 数据类型之间的关系
- 数据类型最大值与最小值之间的关系
- hibernate数据类型之间的映射关系
- JavaScript数据类型和数据类型之间的转换关系
- VB与C++之间数据类型的对应关系
- C#中数据类型与其他语言中的数据类型之间的对应关系
- [C#]Windows API声明中的数据类型与.NET数据类型之间的对照关系
- hibernate+java+sql 之间数据类型转换关系
- java与sql 之间数据类型转换关系
- hibernate+java+sql 之间数据类型转换关系
- java各数据类型之间的转换
- java各数据类型之间的转换
- 数据类型之间的转换
- 数据类型之间的转换
- 数据类型之间的转换
- 数据类型之间的转换
- 数据类型之间的转换
- 基于QML的文件读写
- WiFi辐射新解读
- Apache服务器中如何使用listen指令绑定ip地址和端口
- android 中 EditText加入图标 更改边框颜色 设置透明 代码
- 黑色5.5寸版iPhone 6曝光 部分规格泄露:64位A8处理器+千万级像素
- 各数据类型之间的关系
- POJ训练计划1062_昂贵的聘礼(最短路)
- python位图排序
- 社交分享下一站:手游录像正在走红
- jquery 判断checkbox 是否选中
- ScrollView嵌套 ExpandableListView
- android 自动更新apk版本
- C#海康解码器上大屏代码事例
- cclablettf字体描边实现