平台:Java eclipse
内容:通过charAt(int index)方法查询一个字符串某个字符是什么。index是一个int类型的参数。
内容:实现从键盘中得到一个字符串,使用charAt()方法,就假定我们想要知道第6个字符是什么,设参数为5。(参数从0开始。)
public static void main(String[] args) {
String enterChar;
Scanner sc=new Scanner(System.in);
enterChar=sc.nextLine();
char result=enterChar.charAt(5);
System.out.println(result);
}
然后我们可以从键盘输入以下字符串:
“i love you1314”
然后就得到第6个字符结果为‘e’