比方說,我有一個計劃,轉換字母與數字使得:轉換字母與數字
輸入: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'應該轉化爲什麼? –