<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Java 程序:十進制到十六進制的轉換 > 原文: [https://beginnersbook.com/2014/07/java-program-to-convert-decimal-to-hexadecimal/](https://beginnersbook.com/2014/07/java-program-to-convert-decimal-to-hexadecimal/) 將十進制數轉換為十六進制數有以下兩種方法: 1)使用`Integer`類的[`toHexString()`方法](https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#toHexString(int))。 2)通過編寫自己的邏輯進行轉換,而無需使用任何預定義的方法。 ### 方法 1:使用`toHexString()`方法的十進制到十六進制轉換 ```java import java.util.Scanner; class DecimalToHexExample { public static void main(String args[]) { Scanner input = new Scanner( System.in ); System.out.print("Enter a decimal number : "); int num =input.nextInt(); // calling method toHexString() String str = Integer.toHexString(num); System.out.println("Method 1: Decimal to hexadecimal: "+str); } } ``` **輸出:** ```java Enter a decimal number : 123 Method 1: Decimal to hexadecimal: 7b ``` ### 方法 2:不使用預定義的方法的十進制到十六進制轉換 ```java import java.util.Scanner; class DecimalToHexExample { public static void main(String args[]) { Scanner input = new Scanner( System.in ); System.out.print("Enter a decimal number : "); int num =input.nextInt(); // For storing remainder int rem; // For storing result String str2=""; // Digits in hexadecimal number system char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; while(num>0) { rem=num%16; str2=hex[rem]+str2; num=num/16; } System.out.println("Method 2: Decimal to hexadecimal: "+str2); } } ``` **輸出:** ```java Enter a decimal number : 123 Method 2: Decimal to hexadecimal: 7B ```
                  <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>

                              哎呀哎呀视频在线观看