zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然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)) ;
        }
    };
  • 相关阅读:
    Jmeter_Beanshell_使用Java处理JSON块
    BeanShell Processor_使用Java处理脚本
    MySQL_explain关键字分析查询语句
    LoadRunner11_录制脚本时的浏览器版本
    Jmeter_实现Excel文件导出到本地
    Jmeter_录制HTTPS
    性能测试常用sql语句
    LoadRunner11_MySQL数据库脚本
    LoadRunner11_录制Oracle数据库脚本
    实现liunx之间无密码访问——ssh密匙
  • 原文地址:https://www.cnblogs.com/tszr/p/12153266.html
Copyright © 2011-2022 走看看