日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【蓝桥杯】基础练习 十六进制转十进制

發布時間:2024/9/30 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【蓝桥杯】基础练习 十六进制转十进制 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

試題 基礎練習 十六進制轉十進制

資源限制
時間限制:1.0s 內存限制:512.0MB
問題描述
  從鍵盤輸入一個不超過8位的正的十六進制數字符串,將它轉換為正的十進制數后輸出。
  注:十六進制數中的10~15分別用大寫的英文字母A、B、C、D、E、F表示。
樣例輸入
FFFF
樣例輸出
65535

Java代碼

/*** * 十六進制轉十進制* * @author williamma**/ public class HexadecimalToTen {static String[] ten = { "" };public static void main(String[] args) {Scanner scn = new Scanner(System.in);String num = scn.next();// 輸入十六進制long sum = 0;// 總數for (int i = 0; i < num.length(); i++) {// 循環計算出每位的數相加。switch (num.charAt(i)) {case '0': {sum += 0 * Math.pow(16, (num.length() - 1 - i));break;}case '1': {sum += 1 * Math.pow(16, (num.length() - 1 - i));break;}case '2': {sum += 2 * Math.pow(16, (num.length() - 1 - i));break;}case '3': {sum += 3 * Math.pow(16, (num.length() - 1 - i));break;}case '4': {sum += 4 * Math.pow(16, (num.length() - 1 - i));break;}case '5': {sum += 5 * Math.pow(16, (num.length() - 1 - i));break;}case '6': {sum += 6 * Math.pow(16, (num.length() - 1 - i));break;}case '7': {sum += 7 * Math.pow(16, (num.length() - 1 - i));break;}case '8': {sum += 8 * Math.pow(16, (num.length() - 1 - i));break;}case '9': {sum += 9 * Math.pow(16, (num.length() - 1 - i));break;}case 'A': {sum += 10 * Math.pow(16, (num.length() - 1 - i));break;}case 'B': {sum += 11 * Math.pow(16, (num.length() - 1 - i));break;}case 'C': {sum += 12 * Math.pow(16, (num.length() - 1 - i));break;}case 'D': {sum += 13 * Math.pow(16, (num.length() - 1 - i));break;}case 'E': {sum += 14 * Math.pow(16, (num.length() - 1 - i));break;}case 'F': {sum += 15 * Math.pow(16, (num.length() - 1 - i));break;}}}System.out.println(sum);// 輸出}}

總結

以上是生活随笔為你收集整理的【蓝桥杯】基础练习 十六进制转十进制的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。