编写一个名为的方法,该方法inputBirthday
接受控制台的 Scanner 作为参数并提示用户输入出生年月日,然后以合适的格式打印出生日期。这是与用户的示例对话:
On what day of the month were you born? 8
What is the name of the month in which you were born? May
During what year were you born? 1981
You were born on May 8, 1981. You're mighty old!
所以这就是我所做的:
import java.util.Scanner;
public static void inputBirthday(int month,String day,int year){
Scanner sc=new Scanner(System.in);
System.out.print("On what day of the month were you born?");
month=sc.nextInt();
System.out.print("What is the name of the month in which you were born?");
day=sc.nextLine();
System.out.print("During what year were you born?");
year=sc.nextInt();
}
我的代码编译失败。有人可以给我一些提示,我会自己尝试一下。