System.out.print("Enter max record: "); //Entering max record
int numOfRecords = sc.nextInt();//using scanner, scan the number of records
System.out.print("Enter Name: ");//Entering Name
String name1 = sc.next();
System.out.print("Enter Gender(Male or Female): ");//Entering Gender
String gender1 = sc.next();
System.out.print("Enter Month of Birth: ");//Display Enter month of Birth
String monOfBirth1 = sc.next(); //Month
System.out.print("Enter Day of Birth: ");//Birth
double dayOfBirth1 = sc.nextDouble();
System.out.print("Enter Year of Birth: ");
double yearOfBirth1 = sc.nextDouble();
for (int i =0; i< numOfRecords-1; i++) {
System.out.print("Enter Name: ");//My follow up for looping
String name = sc.next();
System.out.print("Enter Gender: ");//same as in gender
String gender = sc.next();
System.out.print("Enter Month of Birth: ");//same as in month
String monOfBirth = sc.next();//scan the Month of Birth
System.out.print("Enter Day of Birth: ");//and day
double dayOfBirth = sc.nextDouble();//scan the day of birth
System.out.print("Enter Year of Birth: ");//Display Enter year of Birth
double yearOfBirth = sc.nextDouble();//scan
if (yearOfBirth>yearOfBirth1){//Before I use a student record as my preference thats why i use this yearOfBirth
name1 = name; //I use this to add in the enter max record
gender1 = gender; //same as this
monOfBirth1 = monOfBirth; //and so on
dayOfBirth1 = dayOfBirth; //and so on
yearOfBirth1 = yearOfBirth; //and for the last the year of birth
}
}
System.out.println("NAME\t\tGENDER\t\tBIRTH DATE \t AGE"); //the title of the code
System.out.printf("%s\t\t%s\t\t%s %g,%f \t %d Years Old", name1, gender1,
monOfBirth1,dayOfBirth1,yearOfBirth1,yearOfBirth1-2021); //This is the output of my code
如果我输入最多3条记录,我想这样显示
Name Gender Birthdate Age //I want this to display in my output
joselito male 2001年11月28日19岁//如果我输入3条记录,我想要这个输出,尽管输出中的生日、生日和生日是分开的,但它们必须混合joselito male 2001年11月28日19岁joselito male 2001年11月28日19岁
我想通过减去2021年的出生年份来显示年龄。
但它看起来像这样,如果我在max记录中输入3
Name Gender Birthdate Age //But it looks like this when i run the program
Joselito Male Nov. 28.0000, 2001.00000 //and error
错误显示:
线程“main”java.util.illegalformatconversionexception中出现异常:d!=java.base/java.util.formatter$formatspecifier.failconversion(formatter.java:4445)java.base/java.util.formatter$formatspecifier.printinteger(formatter.java:2957)java.base/java.util.formatter$formatspecifier.print(formatter.java:2911)java.base/java.util.formatter.formatter.format(formatter.java:2689)atjava.base/java.io.printstream.format(printstream.java:1209)位于java.base/java.io.printstream.printf(printstream.java:1105)
暂无答案!
目前还没有任何答案,快来回答吧!