我正在编写一个程序,该程序从从命令行重定向的文本文件中解码秘密消息。第一行是关键短语,第二行是索引关键短语的一组整数。我正在尝试使用该charAt()
方法,但我不断收到没有此类元素异常错误消息。
public class Decoder
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
while (keyboard.hasNext())
{
String phrase = keyboard.nextLine();
int numbers = keyboard.nextInt();
char results = phrase.charAt(numbers);
System.out.print(results);
}
}
}