Java基本数据类型转换
2014-12-10 14:25
281 查看
public class TestConvert {
public static void main(String arg[])
{
int i1 = 123;
int i2 = 456;
double d1 = (i1+i2)*1.2;//系统将转换为double型运算
float f1 = (float)((i1+i2)*1.2);//需要加强制转换符
byte b1 = 67;
byte b2 = 89;
byte b3 = (byte)(b1+b2);//系统将转换为int型运算,需
//要强制转换符
System.out.println(b3);
double d2 = 1e200;
float f2 = (float)d2; //会产生溢出
System.out.println(37美食网www.37meishi.com);
float f3 = 1.23f;//必须加f
long l1 = 123;
long l2 = 30000000000L;//必须加l
float f = l1+l2+f3;//系统将转换为float型计算
long l = (long)f;//强制转换会舍去小数部分(不是四舍五入)
}
}
public class TestConvert2 {
public static void main(String[] args) {
int i=1,j=12;
float f1=(float)0.1; //0.1f
float f2=123;
long l1 = 12345678,l2=8888888888L;
double d1 = 2e20,d2=124;
byte b1 = 1,b2 = 2,b3 = 127;
j = j+10;
i = i/10;
i = (int)(i*0.1);
char c1='a',c2=125;
byte b = (byte)(b1-b2);
char c = (char)(c1+c2-1);
float f3 = f1+f2;
float f4 = (float)(f1+f2*0.1);
double d = d1*i+j;
float f = (float)(d1*5+d2);
}
}
public static void main(String arg[])
{
int i1 = 123;
int i2 = 456;
double d1 = (i1+i2)*1.2;//系统将转换为double型运算
float f1 = (float)((i1+i2)*1.2);//需要加强制转换符
byte b1 = 67;
byte b2 = 89;
byte b3 = (byte)(b1+b2);//系统将转换为int型运算,需
//要强制转换符
System.out.println(b3);
double d2 = 1e200;
float f2 = (float)d2; //会产生溢出
System.out.println(37美食网www.37meishi.com);
float f3 = 1.23f;//必须加f
long l1 = 123;
long l2 = 30000000000L;//必须加l
float f = l1+l2+f3;//系统将转换为float型计算
long l = (long)f;//强制转换会舍去小数部分(不是四舍五入)
}
}
public class TestConvert2 {
public static void main(String[] args) {
int i=1,j=12;
float f1=(float)0.1; //0.1f
float f2=123;
long l1 = 12345678,l2=8888888888L;
double d1 = 2e20,d2=124;
byte b1 = 1,b2 = 2,b3 = 127;
j = j+10;
i = i/10;
i = (int)(i*0.1);
char c1='a',c2=125;
byte b = (byte)(b1-b2);
char c = (char)(c1+c2-1);
float f3 = f1+f2;
float f4 = (float)(f1+f2*0.1);
double d = d1*i+j;
float f = (float)(d1*5+d2);
}
}
相关文章推荐
- java 基本数据类型之间的转换
- java 基本数据类型转换
- Java基本数据类型的转换
- java String和基本数据类型的转换
- Java基本数据类型转换(转)
- java基本数据类型转换
- java基本数据类型转换
- java学习-JAVA基本排序法示例,JAVA数据类型转换 ,ArrayList用法,Calendar 简单应用
- Java基础小知识——基本数据类型和字符串以及字节数组的转换
- 关于java 基本数据类型之间的转换
- Java 基本数据类型和Sting之间的相互转换
- JAVA基本数据类型转换
- java基本数据类型转换
- java 基本数据类型之间的转换
- Java中的移位操作以及基本数据类型转换成字节数组【收集】
- java基本数据类型之间的转换
- Java基本数据类型:long与float之间的转换疑惑
- JAVA第二天变量补码进制转换基本数据类型
- 黑马程序员J_ava学习笔记_Java中的基本数据类型转换详解
- Java基本数据类型的转换