java編程思想_007列印二進位,八進位,十六進位

來源:互聯網
上載者:User
package wzs.test2;//列印二進位,八進位,十六進位public class Test{    public static void main(String[] args)    {        System.out.println("0-20二進位.");        for (int i = 0; i < 20; i++)        {            System.out.print(i + ":" + Integer.toBinaryString(i) + " ");        }        System.out.println("\n0-20八進位.");        for (int i = 0; i < 20; i++)        {            System.out.print(i + ":" + Integer.toOctalString(i) + " ");        }        System.out.println("\n0-20十六進位.");        for (int i = 0; i < 20; i++)        {            System.out.print(i + ":" + Integer.toHexString(i) + " ");        }    }}

輸出結果:

0-20二進位.0:0 1:1 2:10 3:11 4:100 5:101 6:110 7:111 8:1000 9:1001 10:1010 11:1011 12:1100 13:1101 14:1110 15:1111 16:10000 17:10001 18:10010 19:10011 0-20八進位.0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:10 9:11 10:12 11:13 12:14 13:15 14:16 15:17 16:20 17:21 18:22 19:23 0-20十六進位.0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:8 9:9 10:a 11:b 12:c 13:d 14:e 15:f 16:10 17:11 18:12 19:13 

聯繫我們

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