求java程序.题目要求‘程序编完后输入某人身份证号后运行输出该人的出生日期,性别,年龄.’
求java程序.题目要求‘程序编完后输入某人身份证号后运行输出该人的出生日期,性别,年龄.’
身份证倒数第二位是判别姓名的(1为男,2为女),求朋友帮忙
可以在这个上改“ public class Test {
int i, n = 0;
public String test(String a) {
int age = 0;// 年龄
String brithday = "";// 生日
if (a.length() < 18) {
return "输入的身份证号码有误";
}
brithday = a.substring(10, 14);
age = 2010 - Integer.parseInt(a.substring(6, 10));
return "年龄为:" + age + " 生日为:" + brithday;
}
public static void main(String args[]) {
Test t = new Test();
String result = t.test("37022119810518028X");
System.out.println(result);
}
}”
结果:
年龄为:29 生日为:0518