Java的包装类

public class summation_integer {
    public static void main(String[] args){

        //integer_ceshi();
        //boolean_ceshi();
        //byte_ceshi();
        //character_ceshi();
        double_ceshi();
    }
    public static void integer_ceshi(){
        //Integer类,int是32位的带符号位的二进制数,范围为负2的31次方到正的2的31次方-1
        int maxint = Integer.MAX_VALUE;
        int minint = Integer.MIN_VALUE;
        int intsize = Integer.SIZE;
        String str1 = Integer.toString(123);    //10进制,将int转换成string类型
        String str2 = Integer.toBinaryString(123);  //2进制,将int转换成string类型
        String str3 = Integer.toHexString(123);   //16进制,将int转换成string类型
        String str4 = Integer.toOctalString(123);   //8进制,将int转换成string类型
        String str[] ={"12","34"};
        int sum = 0;
        for(int i = 0;i < str.length;i++){
            int intstr = Integer.parseInt(str[i]);   //将string转换成int类型
            sum = sum + intstr;
        }
        //System.out.println("str数组所有数相加和="+sum);
        //System.out.println(str1);
        //System.out.println(str2);
        //System.out.println(str3);
        //System.out.println(str4);
        //System.out.println(maxint);
        //System.out.println(minint);
        System.out.println(Integer.compare(maxint,minint));   //比较两个int对象,第一个小于第二个返回负数,大于返回正数,等于返回0
        //System.out.println(intsize);
    }
    public static void boolean_ceshi(){
        //Boolean类
        Boolean b1 = new Boolean(true);
        Boolean b2 = new Boolean("TRUE");
        Boolean b3 = new Boolean("ok");     //Boolean(String str)当str是不分大小写的true时,他的Boolean值才是true
        Boolean b4 = Boolean.parseBoolean("true");    //将string类型转换成Boolean
        Boolean b5 = Boolean.valueOf("no");        //将string类型转换成Boolean
        System.out.println("b1和b2是否相等?"+b1.equals(b2)+",b1="+b1+",b2="+b2+",b3="+b3);  //equals判断两个Boolean对象是否相等
        System.out.println("b3="+b3.booleanValue());    //将Boolean对象以对应的Boolean值输出
        System.out.println("b3="+b3.toString()+",b4="+b4+",b5="+b5);    //将Boolean对象转换成string类型
    }
    public static void byte_ceshi(){
        //Byte类,byte是8位的带符号的二进制数[-128.127]
        Byte b = new Byte("123");
        Byte b6 = Byte.valueOf("123");   //返回一个Byte对象
        Byte b7 = Byte.parseByte("123");   //string转成Byte
        Boolean b8 = b6.equals(b7);
        System.out.println(b+"\n"+b.byteValue()+"\n"+b.doubleValue()+"\n"+b.intValue()+"\n"+b.toString());
        //byteValue返回byte值,doubleValue返回double类型,intValue返回int型,toString返回string类型
        System.out.println(b6+","+","+b7+","+b8);
    }
    public static void character_ceshi(){
        Character a1 = new Character('a');
        a1 = 'b';
        System.out.println(a1+"\n"+a1.charValue()+"\n"+a1.toString()+"\n"+Character.toUpperCase(a1)+"\n"+Character.isUpperCase(a1));
    }
    public static void double_ceshi(){
        Double d = new Double(111.125);
        Float f = new Float(11.11);
        System.out.println(d+","+f);
    }
    }


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页