java --基礎資料型別 (Elementary Data Type)間的轉換

來源:互聯網
上載者:User

標籤:parse   get   float   val   利用   必須   color   ati   stat   

public class changetype {     public static void main(String[] args)     {          String ar = "true";  //String轉 boolean ,只要不是"true",結果即為false;        boolean ar1 = Boolean.parseBoolean(ar);        if(ar1)        {            System.out.println("true");   //結果為true;        }                String str = "12";    //String 轉   int        int m = Integer.parseInt(str);        System.out.println(m);                String str0 = "12.6";             //string轉換成double        double x = Double.parseDouble(str0);        System.out.println(x);                int y = 5;        String str1 = y+"";        System.out.println(str1);                int flag = 100;         //int轉String,任何類型與字串串連將變為字串類型。不推薦使用        String a = flag+"";        System.out.println(a);                 int flag0 = 200;               //int 轉String 利用String.valueOf();        String str3 = String.valueOf(flag0);        System.out.println(str3);                float h = 12.6f;  //  float 轉 int ,由高到低必須進行強制類型轉換,損失精度變為12        int w =(int)h;        System.out.println(w);    //結果為12                float c = 89.6666f;        double s = c;        System.out.println(s);    //結果為89.666677987979                double e = 78.999999999;        float o = (float)e;        System.out.println(o);   //結果為79                                     }}

 

java --基礎資料型別 (Elementary Data Type)間的轉換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.