第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將七段轉(zhuǎn)換為數(shù)字

將七段轉(zhuǎn)換為數(shù)字

牛魔王的故事 2023-08-09 15:05:43
我想在java中將七段數(shù)字轉(zhuǎn)換為普通字符串。例如,如果輸入這樣的字符串輸入   _  _     _  _  _  _  _  _    | _| _||_||_ |_   ||_||_|| | ||_  _|  | _||_|  ||_| _||_|輸出應(yīng)該像1234567890我找到了這個(gè) JavaScript答案,我正在嘗試將其轉(zhuǎn)換為 java?,F(xiàn)在我有:private static void get7segment(String ascii)     {        String[] splited="909561432".split("");        HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();        map.put(0, 63);        map.put(1, 6);        map.put(2, 91);        map.put(3, 79);        map.put(4, 102);        map.put(5, 109);        map.put(6, 125);        map.put(7, 7);        map.put(8, 127);        map.put(9, 111);                }如有任何幫助,將不勝感激
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

public static void main(String[] args) {

String example= " _? ? ?_? _? ? ?_? _? _? _? _ \n| |? | _| _||_||_ |_? ?||_||_| \n|_|? ||_? _|? | _||_|? ||_| _|";

? ? ? ? System.out.println(get7segment(example));

}


? ? private static String get7segment(String ascii) {

? ? ? ? String result = "";


? ? ? ? String[] lines = ascii.split("\n");

? ? ? ? String[] line1;

? ? ? ? String[] line2;

? ? ? ? String[] line3;


? ? ? ? for (int j = 0; j < lines.length - 2; j += 4) {

? ? ? ? ? ? line1 = lines[j].split("");

? ? ? ? ? ? line2 = lines[j + 1].split("");

? ? ? ? ? ? line3 = lines[j + 2].split("");


? ? ? ? ? ? String pow = "";

? ? ? ? ? ? int mod = 3;


? ? ? ? ? ? for (int i = 0; i < line1.length; i++) {

? ? ? ? ? ? ? ? if (i % mod == 0) {

? ? ? ? ? ? ? ? ? ? String strAs = digitToString(pow);


? ? ? ? ? ? ? ? ? ? result += strAs;

? ? ? ? ? ? ? ? ? ? pow = "";

? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? if (line1[i].equals("_") && i % mod == 1)

? ? ? ? ? ? ? ? ? ? pow += "0";


? ? ? ? ? ? ? ? if (line2[i].equals("|") && i % mod == 0)// left

? ? ? ? ? ? ? ? ? ? pow += "5";

? ? ? ? ? ? ? ? if (line2[i].equals("|") && i % mod == 2)// right

? ? ? ? ? ? ? ? ? ? pow += "1";

? ? ? ? ? ? ? ? if (line2[i].equals("_") && i % mod == 1)// bottom

? ? ? ? ? ? ? ? ? ? pow += "6";


? ? ? ? ? ? ? ? if (line3[i].equals("|") && i % mod == 0)// left

? ? ? ? ? ? ? ? ? ? pow += "4";

? ? ? ? ? ? ? ? if (line3[i].equals("|") && i % mod == 2)// right

? ? ? ? ? ? ? ? ? ? pow += "2";

? ? ? ? ? ? ? ? if (line3[i].equals("_") && i % mod == 1)// bottom

? ? ? ? ? ? ? ? ? ? pow += "3";


? ? ? ? ? ? ? ? if (line1.length - 1 == i) {

? ? ? ? ? ? ? ? ? ? String strAs = digitToString(pow);

? ? ? ? ? ? ? ? ? ? result += strAs;

? ? ? ? ? ? ? ? ? ? pow = "";

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }



? ? ? ? ? ? result += "\n";

? ? ? ? }

? ? ? ? return result;

? ? }


? ? /*

? ? ?* Converting single ascii digit to regular digit

? ? ?*/

? ? private static String digitToString(String asciiDigit) {

? ? ? ? if (asciiDigit == null || asciiDigit.equals(""))

? ? ? ? ? ? return "";

? ? ? ? int pow = 0;

? ? ? ? for (int i = 0; i < asciiDigit.length(); i++)

? ? ? ? ? ? pow += Math.pow(2, Character.getNumericValue(asciiDigit.charAt(i)));


? ? ? ? HashMap<Integer, Integer> map = new HashMap<Integer, Integer>() {

? ? ? ? ? ? {

? ? ? ? ? ? ? ? put(63, 0);

? ? ? ? ? ? ? ? put(6, 1);

? ? ? ? ? ? ? ? put(91, 2);

? ? ? ? ? ? ? ? put(79, 3);

? ? ? ? ? ? ? ? put(102, 4);

? ? ? ? ? ? ? ? put(109, 5);

? ? ? ? ? ? ? ? put(125, 6);

? ? ? ? ? ? ? ? put(7, 7);

? ? ? ? ? ? ? ? put(127, 8);

? ? ? ? ? ? ? ? put(111, 9);

? ? ? ? ? ? }

? ? ? ? };

? ? ? ? return map.containsKey(pow) ? Integer.toString(map.get(pow)) : "?";

? ? }

輸出:


0123456789


查看完整回答
反對(duì) 回復(fù) 2023-08-09
  • 1 回答
  • 0 關(guān)注
  • 112 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)