java 中封裝類

來源:互聯網
上載者:User

標籤:integer構造方法和常用方法

java中八種基礎資料型別 (Elementary Data Type)對應的封裝類型:基礎資料型別 (Elementary Data Type)封裝類型bytejava.lang.Byte;shortjava.lang.Short;intjava.lang.Integer;longjava.lang.Long;floatjava.lang.Float;double      java.lang.Double;booleanjava.lang.Boolean;charjava.lang.Character;/*以java.lang.Integer;類型為例,講解八種類型。*/public class IntegerTest02{public static void main(String[] args){//擷取int類型的最大值和最小值System.out.println("int最小值:" + Integer.MIN_VALUE);System.out.println("int最大值:" + Integer.MAX_VALUE);//以int推byteSystem.out.println("byte最小值:" + Byte.MIN_VALUE);System.out.println("byte最大值:" + Byte.MAX_VALUE);//建立Integer類型的對象Integer i1 = new Integer(10); //int--> IntegerInteger i2 = new Integer("123"); //String --> IntegerSystem.out.println(i1); //10System.out.println(i2); //123//以下程式編譯可以通過。但是啟動並執行時候會報異常.數字格式化異常.//雖然可以將字串轉換成Integer類型,但是該字串也必須是"數字字串".//Integer i3 = new Integer("abcd"); //NumberFormatExceptionInteger的常用方法:public class IntergerTest{    public static void main(String[] args){    //int--》interger 基礎資料型別 (Elementary Data Type)-》引用資料類型    Interger i1=new Integer(10);    Integer i1=Integer.valueOf(10);    //    int i2= i1.intValue();    //String-->Integer    Integer i3=New Integer("10");    Integer i4=Integer.valueOf("10");    //** String-》int    int i4=Integer.parseInt("25");    //*****String->>double    Double i5=Double.parseDouble("30.111");//將int類型的十進位轉換成16進位String s2 = Integer.toHexString(10);System.out.println(s2); //a//將int類型的十進位轉換成8進位String s3 = Integer.toOctalString(10);System.out.println(s3); //12     }}


本文出自 “gaogaozi” 部落格,請務必保留此出處http://hangtiangazi.blog.51cto.com/8584103/1662485

java 中封裝類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.