import java.util.Scanner;
public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        StringBuilder year = new StringBuilder();
        StringBuilder month = new StringBuilder();
        StringBuilder day = new StringBuilder();
        year.append(str.charAt(0));
        year.append(str.charAt(1));
        year.append(str.charAt(2));
        year.append(str.charAt(3));
        month.append(str.charAt(4));
        month.append(str.charAt(5));
        day.append(str.charAt(6));
        day.append(str.charAt(7));
        System.out.println("year=" + year);
        System.out.println("month=" + month);
        System.out.println("date=" + day);
    }
}

第一反应是用StringBuilder配合append,看了别人的题解,感觉被自己蠢死,哈哈哈。完全可以使用substring啊!

import java.util.Scanner;
public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println("year=" + str.substring(0,4));
        System.out.println("month=" + str.substring(4,6));
        System.out.println("date=" + str.substring(6,8));
    }
}