常用數制的輸入與輸出(JAVA)

來源:互聯網
上載者:User

標籤:數制的輸入與輸出

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package c2_1;/** * * @author pc */public class C2_1 {    /**     * @param args the command line arguments     */    public static void main(String[] args) {        byte a1=0071;//八位元        byte a2=10;//十進位數        byte a3=0x21;//十六進位數        int b1,b2,i1=4;        short c1=0x1e2;        long d=0x10ef,d1=1234567;        b1=b2=15;        System.out.println("sum="+(1+5));        System.out.print("a1=0"+Integer.toOctalString(a1)+"(八進位輸出)");        System.out.print("\ta1="+a1);//按十進位輸出        System.out.print("\ta2="+a2);        System.out.print("\ta3=0x"+Integer.toHexString(a3)+"(按十六進位輸出)");        System.out.println("\ta3="+a3);//按十進位輸出        System.out.print("i1="+Integer.toBinaryString(i1)+"(二進位輸出)");        System.out.print("\ti1="+i1);        System.out.print("\tb1="+b1);        System.out.print("\tb2="+b2);        System.out.format("c1=0x"+"%x",c1);        System.out.print("\tc1="+c1);        System.out.print("\td="+d);        System.out.print("\td1="+d1);    }}

運行結果


run:sum=6a1=071(八進位輸出)   a1=57   a2=10   a3=0x21(按十六進位輸出)    a3=33i1=100(二進位輸出)   i1=4    b1=15   b2=15c1=0x1e2   c1=482  d=4335  d1=1234567成功構建 (總時間: 1 秒)


本文出自 “桑海田 部落格專欄” 部落格,請務必保留此出處http://10602803.blog.51cto.com/10592803/1683049

常用數制的輸入與輸出(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.