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

代码如下:

package com.homework.lhh;

import java.util.Scanner;

public class Ex03 {
    String year;
    String month;
    String day;
    static String id;
    @SuppressWarnings("resource")
    public void InputId() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的身份证号:");
        id = sc.nextLine();
    }
    public void CutId(String id){
        year = id.substring(6, 10);// 截取年
        month = id.substring(10, 12);// 截取月份
        day = id.substring(12, 14);// 截取天
    }
    public String toString(){
        return "你的生日是:" + year + " 年 " + month + " 月 " + day + " 日。";
    }
    public static void main(String[] args) {
        Ex03 peopleId = new Ex03();
        peopleId.InputId();
        peopleId.CutId(id);
        System.out.println(peopleId.toString());
    }

}

运行结果如图:

java根据身份证得到生日 java从身份证从提取生日_java