地铁运营调试:帮我补充一断JAVA程序

来源:百度文库 编辑:高考问答 时间:2024/04/29 08:20:07
由基本数据类型的值构建包装类对象
(1) 程序功能:创建每一种基本数据类型对应的包装器类对象,对比输出基本数据类型和对应的包装器类的类名。
(2) 程序源代码如下。
public class WrapperToPrimary{
public static void main(String[] args) {
WrapperToPrimary test=new WrapperToPrimary();
test.testConvertToWrapper();
}
protected void testConvertToWrapper(){
byte b=(byte)127;
Byte B=new Byte(b);
System.out.println(byte.class.getName()+"->"+B.getClass().getName()+":"+b+"->"+B.byteValue());
char c=(char)80;
Character C=new Character(c);
System.out.println(char.class.getName()+"->"+C.getClass().getName()+":"+c+"->"+C.charValue());
short s=(short)32767;
Short S=new Short(s);
System.out.println(short.class.getName()+"->"+S.getClass().getName()+":"+s+"->"+S.shortValue());
int i=100000;
Integer I=new Integer(i);
System.out.println(int.class.getName()+"->"+I.getClass().getName()+":"+i+"->"+I.intValue());
}
}
从包装类对象中得到基本数据类型的值
(1) 程序功能:创建每一种包装器类的对象,获取包装器类对象中包含的基本数据类型的值,并对比输出基本数据类型和对应的包装器类的类名。
(2) 程序源代码如下。
public class PrimaryToWrapper{
public static void main(String[] args) {
PrimaryToWrapper test=new PrimaryToWrapper ();
test. testWrapperToConvert ();
}
protected void testWrapperToConvert (){
Byte B=new Byte(100);
byte b= B.byteValue()
System.out.println(B.getClass().getName()+"->"+byte.class.getName()+":"+B.byteValue()+"->"+b);
// 模仿前面的代码,补充针对包装器类Character,Short,Integer转换的代码
Character C=new Character(‘A’);
……
Short S=new Short(128);
……
Integer I=new Integer(10000);
……
}
}
我发表的JAVA程序里标点有的是全角的