【发布时间】:2018-11-04 15:23:59
【问题描述】:
方法String toBase64(Integer[] decimalCh)接受一个从0到63的整数数组,并根据base64表返回一个编码字符串:
private static final char b64[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
我想实现方法,让每个整数都匹配表中的索引字符,例如:
Integer[] decChar = {37, 62, 37, 43, 0}
String result = toBase64(decChar);
输出:l+lrA
我试图通过嵌套循环来实现它,但它似乎不是一个准确的方法
public static String toBase64(Integer[] decimalCh) {
String result = "";
for (int i = 0; i < decimalCh.length; i++) {
for(int j = 0; j < b64.length; j++) {
result += b64[j];
}
}
return result;
【问题讨论】:
-
您使用什么语言和框架?到目前为止,您尝试了什么,它是如何起作用的?请阅读how to ask good questions 和this question checklist。最后学习如何创建Minimal, Complete, and Verifiable Example。
-
我已经添加了我的方法实现