比方说,我有一个计划,转换字母与数字使得:转换字母与数字
输入:ABCD
输出:1234
- 我怎么能转换ABCD至1234高效
- 以及如何从令牌中提取每个单独的字符
B顺便说一句,这不是功课。 (这是为了好玩)
这是我到目前为止有:
public class Test {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("test.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out.txt")));
StringTokenizer st = new StringTokenizer(f.readLine());
int i1 = Integer.parseInt(st.nextToken());
// How can I convert this into integers? (where a = 1, b = 2, and c = 3)
out.println(????);
out.close();
System.exit(0);
}
}
大写字母,将其转换为ASCII,减去 'A',再加入1 –
你的问题需要更多的规范。例如,'wxyz'应该转化为什么? –