/*
输入年月日,判断多少岁
*/
import javax.swing.*;
import java.text.*;
import java.util.*;
class xxx
{
public static void main(String [] args)
{
String aaa,bbb,ccc;
int a,year,mon,day,age,nyear,nmon,nday,nage,xage;
Date today = new Date();
GregorianCalendar cal = new GregorianCalendar();
nyear = cal.get(Calendar.YEAR);
nmon = cal.get(Calendar.MONTH);
nday = cal.get(Calendar.DATE);
aaa = JOptionPane.showInputDialog(null,"请输入你的生日的年份:");
year = Integer.parseInt(aaa);
bbb = JOptionPane.showInputDialog(null,"请输入你的生日月份:");
mon =Integer.parseInt(bbb);
ccc = JOptionPane.showInputDialog(null,"请输入你的生日日期:");
day = Integer.parseInt(ccc);
if(nyear>year||nmon>=mon)
{
age = nyear-year;
JOptionPane.showMessageDialog(null,"你的出生是:"+
year+"年"+mon+"月"+day+"日"+"\n"
+"你今年是:" + age+"岁");
}
else if(nyear>year||nmon>=mon||nday<=day)
{
nage = nyear-year-1;
JOptionPane.showMessageDialog(null,"你的出生是:"+
year+"年"+mon+"月"+day+"日"+"\n"
+"你今年是:" + nage+"岁");
}
else
{
xage = nyear-year-1;
JOptionPane.showMessageDialog(null,"你的出生是:"+
year+"年"+mon+"月"+day+"日"+"\n"
+"你今年是:" + xage+"岁");
}
}
}
输入年月日,判断多少岁
*/
import javax.swing.*;
import java.text.*;
import java.util.*;
class xxx
{
public static void main(String [] args)
{
String aaa,bbb,ccc;
int a,year,mon,day,age,nyear,nmon,nday,nage,xage;
Date today = new Date();
GregorianCalendar cal = new GregorianCalendar();
nyear = cal.get(Calendar.YEAR);
nmon = cal.get(Calendar.MONTH);
nday = cal.get(Calendar.DATE);
aaa = JOptionPane.showInputDialog(null,"请输入你的生日的年份:");
year = Integer.parseInt(aaa);
bbb = JOptionPane.showInputDialog(null,"请输入你的生日月份:");
mon =Integer.parseInt(bbb);
ccc = JOptionPane.showInputDialog(null,"请输入你的生日日期:");
day = Integer.parseInt(ccc);
if(nyear>year||nmon>=mon)
{
age = nyear-year;
JOptionPane.showMessageDialog(null,"你的出生是:"+
year+"年"+mon+"月"+day+"日"+"\n"
+"你今年是:" + age+"岁");
}
else if(nyear>year||nmon>=mon||nday<=day)
{
nage = nyear-year-1;
JOptionPane.showMessageDialog(null,"你的出生是:"+
year+"年"+mon+"月"+day+"日"+"\n"
+"你今年是:" + nage+"岁");
}
else
{
xage = nyear-year-1;
JOptionPane.showMessageDialog(null,"你的出生是:"+
year+"年"+mon+"月"+day+"日"+"\n"
+"你今年是:" + xage+"岁");
}
}
}
但是你只要输入一个具体的时间,就会发现错了!