【发布时间】:2018-03-30 17:19:30
【问题描述】:
Scanner user_input = new Scanner( System.in );
String cipher_input = user_input.nextLine();
String[] arr_cipher_input = cipher_input.split("");
int[] arr_ctext = new int[cipher_input.length()];
for (int i = 0; i < cipher_input.length(); i++) {
arr_ctext[i] = (int) arr_cipher_input[i].charAt(i);
}
上面的代码接受一个输入并将其拆分为一个数组(例如,“hello”变为 [“h”,“e”,“l”,“l”,“o”]),然后我尝试将字符到它们的 ascii 值,这是它在标题中返回错误的地方。它每次都正确转换第一个字符,然后在第二个字符上停止,我似乎不知道为什么。数组长度似乎相同,所以我不确定我做错了什么。我会很感激任何帮助。提前致谢!
【问题讨论】: