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)) ;
        }
    };
  • 相关阅读:
    PHP页面跳转的几种方法
    PHP网站并发测试
    04-上传文件
    01-转>linux命令
    01-CDN的好处
    05-socket.io使用
    04-soket.io使用2 -数据同步简单聊天室效果
    03-socket.io 2.3.0版本的使用-用户请求接口,实时推送给前端数据
    02-转>
    跨域-转>预解析OPTIONS请求
  • 原文地址:https://www.cnblogs.com/tszr/p/12153266.html
Copyright © 2011-2022 走看看