4个回答
展开全部
可以用如下代码实现改功能,输入一个数字27返回AB
String[] array = new String[] { "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" };
int num = 428;
int count = 26;
System.out.println("num/count=" + num/count);
String out = "";
if (num/count != 0) {
out = array[num/count-1];
if (num%count == 0) {
out = out + array[num%count];
System.out.println(out);
} else {
out = out + array[num%count-1];
System.out.println(out);
}
} else {
out = array[num-1];
System.out.println(out);
}
String[] array = new String[] { "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" };
int num = 428;
int count = 26;
System.out.println("num/count=" + num/count);
String out = "";
if (num/count != 0) {
out = array[num/count-1];
if (num%count == 0) {
out = out + array[num%count];
System.out.println(out);
} else {
out = out + array[num%count-1];
System.out.println(out);
}
} else {
out = array[num-1];
System.out.println(out);
}
展开全部
import java.util.HashMap;
import java.util.Iterator;
public class test1 {
/**
* 利用HashMap
* @param args
*/
public static void main(String[] args) {
HashMap<String,String> hm=new HashMap<String,String>();
for(int k=0;k<=26;k++){
int j=k>=1?k:0;
for(int i=1;i<=26;i++){
if(j>=1)
hm.put(k*26+i+"",((char)(j+64))+""+((char)(i+64)));
else
hm.put(k*26+i+"",((char)(i+64))+"");
}
}
Iterator it=hm.keySet().iterator();
while(it.hasNext()){
String key=(String)it.next();
//用列号1、27、28来做测试是否正确
if(key.equals(1+"")||key.equals(27+"")||key.equals(28+"")){
String value=hm.get(key);
System.out.println(value);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
实际就是10进制转换为26进制,可以参考10进制转2进制、8进制、16进制。自己实现试试看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class VersionCode {
public static Integer CodeConvert(String s) {
if (s==null || s.length()==0) return 0;
int n = 0;
char[] cc=s.toCharArray();
for (int i = s.length() - 1, j = 1; i >= 0; i--, j *= 26){
char c = cc[i];
if (c < 'A' || c > 'Z') return 0;
n += ((int)c - 64) * j;
}
return n;
}
public static String CodeConvert(int n) {
String s = "";
while (n > 0){
int m = n % 26;
if (m == 0) m = 26;
s = (char)(m + 64) + s;
n = (n - m) / 26;
}
return s;
}
public static void main(String[] args) {
for (int i=1;i<1000;i++) {
System.out.println("i="+i+" =>"+CodeConvert(i));
}
System.out.println("i=AAA"+" =>"+CodeConvert("AAA"));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询