发布网友 发布时间:2024-10-24 01:15
共4个回答
热心网友 时间:2024-10-24 07:03
public class Change {//是这样吗
public static void main(String[] args) {
String inStr = "AB12D3Za#45";//qqgroup21/77/7/12
StringBuffer outStr = new StringBuffer();
for (int i = 0; i < inStr.length(); i++) {
int c = (int)inStr.charAt(i);
if(65<=c&&c<=91){
outStr.append(c-);
}else{
outStr.append(inStr.charAt(i));
}
}
System.out.println(outStr);
}
}
热心网友 时间:2024-10-24 07:00
编码与字符的联系!例如A的UTF编码是65,B的编码是66,减去55得到10,11
热心网友 时间:2024-10-24 06:57
a = "AB12D3Za#45";
a = a.replace("A","1");
a = a.replace("B","2");
....
...
....
a = a.replace("Z","26");
热心网友 时间:2024-10-24 07:01
public class ReplaceTest {
private static HashMap<Character, String> map = new HashMap<Character, String>();
static {
map.put(Character.valueOf('A'), "1");
map.put(Character.valueOf('B'), "2");
map.put(Character.valueOf('C'), "3");
map.put(Character.valueOf('D'), "4");
map.put(Character.valueOf('E'), "5");
map.put(Character.valueOf('F'), "6");
map.put(Character.valueOf('G'), "7");
map.put(Character.valueOf('H'), "8");
map.put(Character.valueOf('I'), "9");
map.put(Character.valueOf('G'), "10");
map.put(Character.valueOf('K'), "11");
map.put(Character.valueOf('L'), "12");
map.put(Character.valueOf('M'), "13");
map.put(Character.valueOf('N'), "14");
map.put(Character.valueOf('O'), "15");
}
public static String replace(String string) {
char[] cs = string.toCharArray();
StringBuffer sb = new StringBuffer();
int count = 0;
for (int i = 0; i < cs.length; i++) {
count=0;
for (Iterator iterator = map.keySet().iterator(); iterator
.hasNext();) {
Character name = (Character) iterator.next();
System.out.println(name + "and" + cs[i]);
if (name.equals(cs[i])) {
sb.append(map.get(name));
break;
}else {
count++;
}
if (count == map.size()) {
sb.append(cs[i]);
count=0;
}
}
}
return sb.toString();
}
public static void main(String[] args) {
System.out.println(replace("AB12D3Za#45"));
}
}
map.put()后面自己去加,虽然比较麻烦