灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2718回复:0

java例程练习(基础数据类型的包装类)

楼主#
更多 发布于:2012-09-08 09:42

public class Test {
    public static void main(String[] args) {
        Integer i = new Integer(100);
        Double d = new Double("123.456");
        
        int j = i.intValue() + d.intValue();
        float f = i.floatValue() + d.floatValue();
        System.out.println(j);
        System.out.println(f);
        
        double pi = Double.parseDouble("3.1415926");
        double r = Double.valueOf("2.0").doubleValue();
        double s = pi * r * r;
        System.out.println(s);
        
        try {
            int k = Integer.parseInt("1.23");
            System.out.println(k);
        } catch (NumberFormatException e) {
            System.out.println("格式不正确");
        }
        
        System.out.println(Integer.toBinaryString(123) + "B");
        System.out.println(Integer.toHexString(123) + "H");
        System.out.println(Integer.toOctalString(123) + "O");
    }
}


喜欢0 评分0
游客

返回顶部