赞
踩
- package cn.zzx.base.util;
-
- /**
- *
- * 获取类型方法
- *
- */
- public class Change {
-
-
- public static String getType(Object o){ //获取变量类型方法
- return o.getClass().toString(); //使用Object类型的getClass()方法
- }
- }
-
-

- package cn.zzx.base.util;
-
- public class Test {
- public static void main(String[] args) {
-
- double a = 3.8;
- int b = 5;
- int a2 = new Double(a).intValue(); //double类型转换为int类型
- int s2 = a2 + b;
- String s3 = Integer.toString(s2); //int类型转换为String类型
-
- System.out.println("s2的值是:" + s2);
- System.out.println(Change.getType(s2)); //获取数据类型
- System.out.println("s3的值是:"+s3);
- System.out.println(Change.getType(s3)); //获取数据类型
-
-
- }
-
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。