Java输入身份证号获取出生日期

package two;
import java.util.Scanner;
public class IdCard {
	
    public static void main(String[] args) {
    	IdCards peopleId = new IdCards();
        peopleId.InputId();
        peopleId.CutId(IdCards.id);
        System.out.println(peopleId.toString());
    }
}
class IdCards{
	String year;
    String month;
    String day;
    static String id;
    public void InputId() {
    	@SuppressWarnings("resource")
        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 + " 日。";
    }
}

效果展示:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42249896/article/details/88249376