• 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:包装类


    public class WrapperDemo01{
        public static void main(String args[]){
            int x = 30 ;        // 基本数据类型
            Integer i = new Integer(x) ;    // 装箱:将基本数据类型变为包装类
            int temp = i.intValue()    ;// 拆箱:将一个包装类变为基本数据类型
        }
    };
    public class WrapperDemo02{
        public static void main(String args[]){
            float f = 30.3f ;        // 基本数据类型
            Float x = new Float(f) ;    // 装箱:将基本数据类型变为包装类
            float y = x.floatValue()    ;// 拆箱:将一个包装类变为基本数据类型
        }
    };
    public class WrapperDemo03{
        public static void main(String args[]){
            Integer i = 30 ;    // 自动装箱成Integer
            Float f = 30.3f ;    // 自动装箱成Float
            int x = i ;            // 自动拆箱为int
            float y = f ;        // 自动拆箱为float
        }
    };
    public class WrapperDemo04{
        public static void main(String args[]){
            String str1 = "30" ;    // 由数字组成的字符串
            String str2 = "30.3" ;    // 由数字组成的字符串
            int x = Integer.parseInt(str1) ;    // 将字符串变为int型
            float f = Float.parseFloat(str2) ;    // 将字符串变为int型
            System.out.println("整数乘方:" + x + " * " + x + " = " + (x * x)) ;
            System.out.println("小数乘方:" + f + " * " + f + " = " + (f * f)) ;
        }
    };
    public class WrapperDemo05{
        public static void main(String args[]){
            int x = Integer.parseInt(args[0]) ;    // 将字符串变为int型
            float f = Float.parseFloat(args[1]) ;    // 将字符串变为int型
            System.out.println("整数乘方:" + x + " * " + x + " = " + (x * x)) ;
            System.out.println("小数乘方:" + f + " * " + f + " = " + (f * f)) ;
        }
    };
  • 相关阅读:
    [LeetCode]题解(python):094-Binary Tree Inorder Traversal
    [LeetCode]题解(python):093-Restore IP Addresses
    [LeetCode]题解(python):092-Reverse Linked List II
    [LeetCode]题解(python):091-Decode Ways
    第二阶段团队冲刺1
    进度总结报告十三
    梦断代码阅读笔记02
    第一阶段对各组的意见评价
    进度总结报告十二
    软件开发冲刺10
  • 原文地址:https://www.cnblogs.com/tszr/p/12153266.html
Copyright © 2020-2023  润新知