System.out.println("Enter a sentence to get it translated into Pig Latin: ");
String sentence=kb.nextLine();
String[] words = sentence.split(" ");
char a=words.charAt(0);
最佳答案
发生的情况是,words
是一个数组,并且 charAt()
方法是为 String
定义的。所以你想使用:
words[index].charAt(0)
相反,其中index
是String
在数组中的位置。
关于java - 错误 "Cannot find symbol method charAt(int)"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21516210/