我必须找出从出生日期算起的年龄,放在测试班的桌子上。这意味着我必须将现在的日期与所选日期的日期相匹配。此外,我将该方法放在主类中。错误是我一直为插入的所有变量获得 2018。从我的代码(不是全部在这里)中,第一个变量应该是 58 而不是 2018。
这是代码。
public static int ageMeth(String dob) {
dob.split("/");
int years = 0;
String tempDate = "";
boolean month = true;
if (month) {
// gets the month converts
int x = Integer.parseInt(dob.valueOf(0));
int y = Integer.parseInt(dob.valueOf(1));
String xy = Integer.toString(x, y);
int xyNum = Integer.parseInt(xy);
LocalDateTime date = LocalDateTime.now();
tempDate = date.toString();
int p = Integer.parseInt(tempDate.valueOf(5));
int i = Integer.parseInt(tempDate.valueOf(6));
String pi = Integer.toString(p, i);
int piNum = Integer.parseInt(pi);
// the days
int x2 = Integer.parseInt(dob.valueOf(2));
int y2 = Integer.parseInt(dob.valueOf(3));
String xy2 = Integer.toString(x2, y2);
int xyNum2 = Integer.parseInt(xy2);
int p2 = Integer.parseInt(tempDate.valueOf(8));
int i2 = Integer.parseInt(tempDate.valueOf(9));
String pi2 = Integer.toString(p2, i2);
int piNum2 = Integer.parseInt(pi2);
// the year
int x3 = Integer.parseInt(dob.valueOf(4));
int y3 = Integer.parseInt(dob.valueOf(5));
int xx3 = Integer.parseInt(dob.valueOf(6));
int yy3 = Integer.parseInt(dob.valueOf(7));
String xy3 = Integer.toString(x3, y3);
String xxyy3 = Integer.toString(xx3, yy3);
int xyNum3 = Integer.parseInt(xy2);
int xxyyNum3 = Integer.parseInt(xxyy3);
int p3 = Integer.parseInt(tempDate.valueOf(8));
int i3 = Integer.parseInt(tempDate.valueOf(9));
String pi3 = Integer.toString(p3, i3);
int piNum3 = Integer.parseInt(pi3);
largeQ
倚天杖
相关分类