国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

代碼模擬實現十六進制轉換十進制

2019-11-14 15:15:08
字體:
來源:轉載
供稿:網友

public class SexAdecimal{

    PRivate int sum;//
    private static String s = null;//把想要轉換的字符串輸入到里面;

    public static void main(String[] args){

        SexAdecimal a = new SexAdecimal();


        a.char_value(s);

    }
    //------------------------------用于把字符串解析-------------------
    public  void char_value(String s){
        if (s == null) {//判斷.傳進來的是不是null 如果是null 就沒必要往下運算,就直接終止函數運行
            System.out.println( "請輸入一個十六進制的字符串,null不是字符串" );
            return;
        }
        for(int i=0; i < s.length(); ++i){
            char c = s.charAt(s.length()-1-i);//從右往左獲得字符串
            if (int_value(c,i)) {//這個是根據輸入的字符,如果有一位不正確,就終止此函數運行,就不輸出錯誤的結果了
                return;
            }
        }
        if (sum == 0) {
            Integer sum1 = null;
            System.out.println( sum1 );
        }else{
            Integer sum1 = sum;
            System.out.println( sum1 );
        }
    }
    //------------------------------------用于把字符串解析成整型值----------------
    public boolean int_value(char c,int N_Ci_Fang ){//這個方法是把字符轉為整形值
        int i = 0;
        if (c == 'a') {
            i = 10;
        }else if (c == 'b') {
            i = 11;
        }else if (c == 'c') {
            i = 12;
        }else if (c == 'd') {
            i = 13;
        }else if (c == 'e') {
            i = 14;
        }else if (c == 'f') {
            i = 15;
        }else if (c == '0') {
            i = 0;
        }else if (c == '1') {
            i = 1;
        }else if (c == '2') {
            i = 2;
        }else if (c == '3') {
            i = 3;
        }else if (c == '4') {
            i = 4;
        }else if (c == '5') {
            i = 5;
        }else if (c == '6') {
            i = 6;
        }else if (c == '7') {
            i = 7;
        }else if (c == '8') {
            i = 8;
        }else if (c == '9') {
            i = 9;
        }else{
            System.out.println( "十六進制每位上的值最大為 f , 請輸入 0~f 之間的值" );
            return true;
        }

        sum_value(i,N_Ci_Fang);
        return false;
    }
    //-----------------------------------用于把整型值計算,得出十進制----------------
    public  void sum_value( int value,int N_Ci_Fang){


        //  System.out.println(   Math.pow(16,0)); //是16的0次方 里面的兩個參數都是double類型
        this.sum += value*(int)Math.pow(16,N_Ci_Fang);
    }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 垦利县| 双流县| 新和县| 长丰县| 蓬莱市| 怀安县| 敦煌市| 和林格尔县| 永州市| 潢川县| 庆城县| 龙胜| 习水县| 葵青区| 凯里市| 项城市| 寻甸| 邳州市| 绵竹市| 龙游县| 巴彦淖尔市| 拜城县| 永泰县| 陆川县| 尤溪县| 许昌市| 库尔勒市| 丹棱县| 五峰| 石嘴山市| 南投县| 沧源| 余庆县| 漾濞| 宜春市| 北碚区| 宣武区| 凭祥市| 沙坪坝区| 贞丰县| 五华县|