<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### [`Formatter`轉換](https://lingcoder.gitee.io/onjava8/#/book/18-Strings?id=formatter-%e8%bd%ac%e6%8d%a2) 下面的表格展示了最常用的類型轉換: | 類型 | 含義 | | :-: | :-- | | `d` | 整型(十進制) | | `c` | Unicode字符 | | `b` | Boolean值 | | `s` | String | | `f` | 浮點數(十進制) | | `e` | 浮點數(科學計數) | | `x` | 整型(十六進制) | | `h` | 散列碼(十六進制) | | `%` | 字面值“%” | 下面的程序演示了這些轉換是如何工作的: ~~~ // strings/Conversion.java import java.math.*; import java.util.*; public class Conversion { public static void main(String[] args) { Formatter f = new Formatter(System.out); char u = 'a'; System.out.println("u = 'a'"); f.format("s: %s%n", u); // f.format("d: %d%n", u); f.format("c: %c%n", u); f.format("b: %b%n", u); // f.format("f: %f%n", u); // f.format("e: %e%n", u); // f.format("x: %x%n", u); f.format("h: %h%n", u); int v = 121; System.out.println("v = 121"); f.format("d: %d%n", v); f.format("c: %c%n", v); f.format("b: %b%n", v); f.format("s: %s%n", v); // f.format("f: %f%n", v); // f.format("e: %e%n", v); f.format("x: %x%n", v); f.format("h: %h%n", v); BigInteger w = new BigInteger("50000000000000"); System.out.println( "w = new BigInteger(\"50000000000000\")"); f.format("d: %d%n", w); // f.format("c: %c%n", w); f.format("b: %b%n", w); f.format("s: %s%n", w); // f.format("f: %f%n", w); // f.format("e: %e%n", w); f.format("x: %x%n", w); f.format("h: %h%n", w); double x = 179.543; System.out.println("x = 179.543"); // f.format("d: %d%n", x); // f.format("c: %c%n", x); f.format("b: %b%n", x); f.format("s: %s%n", x); f.format("f: %f%n", x); f.format("e: %e%n", x); // f.format("x: %x%n", x); f.format("h: %h%n", x); Conversion y = new Conversion(); System.out.println("y = new Conversion()"); // f.format("d: %d%n", y); // f.format("c: %c%n", y); f.format("b: %b%n", y); f.format("s: %s%n", y); // f.format("f: %f%n", y); // f.format("e: %e%n", y); // f.format("x: %x%n", y); f.format("h: %h%n", y); boolean z = false; System.out.println("z = false"); // f.format("d: %d%n", z); // f.format("c: %c%n", z); f.format("b: %b%n", z); f.format("s: %s%n", z); // f.format("f: %f%n", z); // f.format("e: %e%n", z); // f.format("x: %x%n", z); f.format("h: %h%n", z); } } /* Output: u = 'a' s: a c: a b: true h: 61 v = 121 d: 121 c: y b: true s: 121 x: 79 h: 79 w = new BigInteger("50000000000000") d: 50000000000000 b: true s: 50000000000000 x: 2d79883d2000 h: 8842a1a7 x = 179.543 b: true s: 179.543 f: 179.543000 e: 1.795430e+02 h: 1ef462c y = new Conversion() b: true s: Conversion@15db9742 h: 15db9742 z = false b: false s: false h: 4d5 */ ~~~ 被注釋的代碼表示,針對相應類型的變量,這些轉換是無效的。如果執行這些轉換,則會觸發異常。 注意,程序中的每個變量都用到了`b`轉換。雖然它對各種類型都是合法的,但其行為卻不一定與你想象的一致。對于`boolean`基本類型或`Boolean`對象,其轉換結果是對應的`true`或`false`。但是,對其他類型的參數,只要該參數不為`null`,其轉換結果永遠都是`true`。即使是數字 0,轉換結果依然為`true`,而這在其他語言中(包括C),往往轉換為`false`。所以,將`b`應用于非布爾類型的對象時請格外小心。 還有許多不常用的類型轉換與格式修飾符選項,你可以在 JDK 文檔中的`Formatter`類部分找到它們。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看