charAt和String的用法

时间:2021-06-28 05:03:00

package charpter2;

import java.util.Scanner;

public class Test {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("请输入您想输入的内容:");
/*int num = sc.nextInt();
System.out.println(num);
String name = sc.next();
System.out.println(name);
boolean answer = sc.nextBoolean();
System.out.println(answer);*/

String str = sc.next();
System.out.println("abcd");
// charAt(参数跟数组差不多都是从0起123等等,第几个就是从0起到该字母为止)
char c = str.charAt(0);
System.out.println(c);
char c1 = str.charAt(3);
System.out.println(c1);

}
}