用JAVA编写一个程序,要求打印基本8中数据类型和其包装类型,并且加上包装类型和基本类型的互相转换

编写一个程序,要求打印基本8中数据类型和其包装类型,并且加上包装类型和基本类型的互相转换

public class Test {

public static void main(String[] args) {

/*8种基本数据类型*/
byte a = 'b';
char b = 'b';
short c = 32767;
int d = 2147483647;
long e = 9223372036854775807L;
float f = 3;
double g = 0.3;
boolean h = true;

/*基本类型转换为包装类型*/
Byte z = a;
Character y = b;
Short x = c;
Integer w = d;
Long v = e;
Float u = f;
Double t = g;
Boolean s = h;

/*包装类型转换为基本类型*/
byte i = z;
char j = y;
short k = x;
int l = w;
long m = v;
float n = u;
double o = t;
boolean p = s;

System.out.println(i);//98
System.out.println(j);//b
System.out.println(k);//32767
System.out.println(l);//2147483647
System.out.println(m);//9223372036854775807
System.out.println(n);//3.0
System.out.println(o);//0.3
System.out.println(p);//true

}
}

来自:求助得到的回答
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-05-10
基本数据类型,例如 int、float、double、boolean、char
等,是不具备对象的特性的,比如基本类型不能调用方法、功能简单。。。,为了让基本数据类型也具备对象的特性, Java
为每个基本数据类型都提供了一个包装类,这样我们就可以像操作对象那样来操作基本数据类型。
基本类型和包装类之间的对应关系:

包装类主要提供了两大类方法:

1. 将本类型和其他基本类型进行转换的方法
2. 将字符串和本类型及包装类互相转换的方法本回答被网友采纳