Java競賽可能會用到的東西

來源:互聯網
上載者:User

標籤:

以下部分內容並非原創,原作者見到還請諒解~

 

大數

String s=”12345”;BigInteger c=BigInteger.valueOf(s);

格式輸出

System.out.printf("%+8.3f\n", 3.14); //"+"表示後面輸出的數字會有加號或減號,正的+,負的- ;8.3f表示輸出浮點數,寬度為8,小數點保持3位有效 System.out.printf("%+-8.3f\n", 3.14);//"-"表示靠左對齊System.out.printf("%08.3f\n", 3.14);//"0"8位寬度中自動補0System.out.printf("%(8.3f\n", -3.14);//"("如果是負數,自動加上( )System.out.printf("%,f\n", 123456.78); //","金錢表示方法,每三位有一個逗號System.out.printf("%x\n", 0x2a3b); //輸出16進位數System.out.printf("%#x\n", 0x2a3b);//輸出帶0x標識的16進位數System.out.printf("老闆:您名字%s,年齡:%3d歲,工資:%,-7.2f\n","ajioy",21,36000.00);System.out.printf("老闆:您名字%1$s,年齡:%2$#x歲\n","ajioy",38); //"n{1}quot;表示用第n個參數

各種進位轉換

int iOct = 0567;//八位元字的聲明,在前面加上0(零)int iTen = 1000;//十進位數位聲明int iHex = 0xAbcd;//十六進位數位聲明,在前面加上0x(零x),x和abcd不區分大小寫 System.out.println("八進位0567裝換成二進位:Integer.toString(iOct, 2)="+Integer.toString(iOct, 2));System.out.println("八進位0567裝換成二進位:Integer.toBinaryString(iOct)="+Integer.toBinaryString(iOct));System.out.println("八進位0567裝換成十進位:Integer.toString(iOct, 10)="+Integer.toString(iOct, 10));System.out.println("八進位0567裝換成十進位:Integer.toString(iOct)="+Integer.toString(iOct));System.out.println("八進位0567裝換成十六進位:Integer.toString(iOct, 2)="+Integer.toString(iOct, 16));System.out.println("八進位0567裝換成十六進位:Integer.toHexString(iOct)="+Integer.toHexString(iOct)); System.out.println(); System.out.println("十進位1000裝換成十六進位:Integer.toString(iTen,16)="+Integer.toString(iTen,16));System.out.println("十進位1000裝換成十六進位:Integer.toHexString(iTen)="+Integer.toHexString(iTen));System.out.println("十進位1000裝換成八進位:Integer.toString(iTen,8)="+Integer.toString(iTen,8));System.out.println("十進位1000裝換成八進位:Integer.toOctalString(iTen)="+Integer.toOctalString(iTen));System.out.println("十進位1000裝換成二進位:Integer.toString(iTen,2)="+Integer.toString(iTen,2));System.out.println("十進位1000裝換成二進位:Integer.toBinaryString(iTen)="+Integer.toBinaryString(iTen)); System.out.println(); System.out.println("十六進位0xAbcd裝換成十進位:Integer.toString(iHex,10)="+Integer.toString(iHex,10));System.out.println("十六進位0xAbcd裝換成十進位:Integer.toString(iHex)="+Integer.toString(iHex));System.out.println("十六進位0xAbcd裝換成八進位:Integer.toString(iHex,8)="+Integer.toString(iHex,8));System.out.println("十六進位0xAbcd裝換成八進位:Integer.toOctalString(iHex)="+Integer.toOctalString(iHex));System.out.println("十六進位0xAbcd裝換成二進位:Integer.toString(iHex,2)="+Integer.toString(iHex,2));System.out.println("十六進位0xAbcd裝換成二進位:Integer.toBinaryString(iHex)="+Integer.toBinaryString(iHex)); System.out.println();//還可將任意進位的整數裝換成其他任意進位的數字System.out.println("十六進位0xAbcd裝換成七進位:Integer.toString(iHex,7)="+Integer.toString(iHex,7)); 程式輸出:八進位0567裝換成二進位:Integer.toString(iOct, 2)=101110111八進位0567裝換成二進位:Integer.toBinaryString(iOct)=101110111八進位0567裝換成十進位:Integer.toString(iOct, 10)=375八進位0567裝換成十進位:Integer.toString(iOct)=375八進位0567裝換成十六進位:Integer.toString(iOct, 2)=177八進位0567裝換成十六進位:Integer.toHexString(iOct)=177十進位1000裝換成十六進位:Integer.toString(iTen,16)=3e8十進位1000裝換成十六進位:Integer.toHexString(iTen)=3e8十進位1000裝換成八進位:Integer.toString(iTen,8)=1750十進位1000裝換成八進位:Integer.toOctalString(iTen)=1750十進位1000裝換成二進位:Integer.toString(iTen,2)=1111101000十進位1000裝換成二進位:Integer.toBinaryString(iTen)=1111101000十六進位0xAbcd裝換成十進位:Integer.toString(iHex,10)=43981十六進位0xAbcd裝換成十進位:Integer.toString(iHex)=43981十六進位0xAbcd裝換成八進位:Integer.toString(iHex,8)=125715十六進位0xAbcd裝換成八進位:Integer.toOctalString(iHex)=125715十六進位0xAbcd裝換成二進位:Integer.toString(iHex,2)=1010101111001101十六進位0xAbcd裝換成二進位:Integer.toBinaryString(iHex)=1010101111001101十六進位0xAbcd裝換成七進位:Integer.toString(iHex,7)=242140

  

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.