java输入自己的身份证号码,并由此号码输出自己的生日,年月日

public class Work03 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
System.out.print(“请输入身份证号:”);
String num = input.nextLine();

        if (num.length() == 18) {
             //subSequence按指定位置截取
            String year = (String) num.subSequence(6, 10);
            String month = (String) num.subSequence(10, 12);
            String day = (String) num.subSequence(12, 14);
            System.out.println("您的生日是:" + year + "年" + month + "月" + day + "日");
            break;

        } else {
            System.out.println("请输入正确的身份证号码:");
        }
    }

    // System.out.println(num.length());
}

}

猜你喜欢

转载自blog.csdn.net/weixin_42337796/article/details/81672740