实验内容和原理:
1、 将布尔型、整型、长整型、双精度型作为参数,实例化相应的包装类对象,并输出对象的数值。
2、 按照“XXXX年XX月XX日 XX时XX分XX秒”的格式,输出当前时间。
1 package work; 2 3 public class Work1 { 4 Boolean b; 5 Integer i; 6 Long l; 7 Double d; 8 public Work1(boolean b, int i, long l, double d) 9 { 10 this.b = new Boolean(b); 11 this.i = new Integer(i); 12 this.l = new Long(l); 13 this.d = new Double(d); 14 System.out.println(this.b); 15 System.out.println(this.i); 16 System.out.println(this.l); 17 System.out.println(this.d); 18 } 19 public static void main(String[] args) { 20 new Work1(true, 99, 1437631334, 5.4451356); 21 } 22 }
1 package work; 2 3 import java.text.DateFormat; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 import java.util.Locale; 7 8 public class work2 { 9 public static void main(String[] args) { 10 Date d = new Date(); 11 DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒", Locale.CHINA); 12 System.out.println(df.format(d)); 13 14 } 15 16 }