题解 | #出生日期输入输出#
出生日期输入输出
https://www.nowcoder.com/practice/4a4a9dd1edb6453ba4a0432319200743
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s=sc.next();
String year=s.substring(0,4);
String month=s.substring(4,6);
String date=s.substring(6,8);
/*substring():截取字符串中介于两个指定下标之间的字符。 用法:
两个参数: 字符串.substring(参数1,参数2); 参数1:字符串截取的起始下标,非负的整数 如果此参数是0,则是从字符串的第一个字符开始截取 参数2:截取结束位置的索引下标 注意:截取的结果,不包括结束位置的字符
一个参数: 字符串.substring(参数); 参数:字符串截取的起始下标 结果:从起始位置至字符串末尾的字符串*/
System.out.println("year="+year);
System.out.println("month="+month);
System.out.println("date="+date);
}
}

查看10道真题和解析