Let’s say I have a program which converts letters to numbers such that:
Input: abcd
Output: 1234
- How can I convert abcd to 1234 efficiently
- and how can I extract every individual char from the token
By the way, this is not homework. (this is for fun)
This is what I have so far:
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);
}
}
Try this: