-
料青山看我应如是
public static void inputBirthday(Scanner input) { Scanner start = new Scanner(System.in); System.out.print("On what day of the month were you born? "); int day = input.nextInt(); System.out.print("What is the name of the month in which you were born? "); String month = input.next(); System.out.print("During what year were you born? "); int year = input.nextInt(); System.out.println("You were born on " + month + " " + day + "," + " " + year + "." + " You're mighty old!");}
-
牛魔王的故事
public static void main(String[] args) { Scanner in = new Scanner(System.in); // either instantiate the enclosing class, or make inputBirthday static inputBirthday(in); } public static void inputBirthday(Scanner abc) { System.out.print("On what day of the month were you born? "); int inputDay = abc.nextInt(); System.out.print("What is the name of the month in which you were born? "); String inputMonth = abc.next(); System.out.print("During what year were you born? "); int inputYear = abc.nextInt(); System.out.println("You were born on " + inputMonth + " " + inputDay + "," + " " + inputYear + "." + " You're mighty old!"); }最后它工作了,代码通过了所有测试
-
米脂
我认为问题在于,要求明确规定你要编写一个名为接受对象的方法。您已经编写了一个方法,然后编写了一个正在接受 的方法。inputBirthdayScannermaininputBirthdayString, int, int将代码从方法移动到方法,删除扫描仪实例化,并修改方法以接受扫描仪(可能是 .maininputBirthdayinputBirthdayinputBirthday(Scanner abc)编写的代码在 intellij 中工作,因为它是一个完整的程序。但对于网站,他们希望有一个特定的方法签名。这种方法与此类在线代码位置所期望的没有什么不同。leetcodeOP进行了编辑,但同样,要求规定该方法应如下所示:public void inputBirthday(Scanner abc) { System.out.println("On what day of the month were you born? "); int inputDay = abc.nextInt(); System.out.println("What is the name of the month in which you were born? "); String inputMonth = abc.next(); System.out.println("During what year were you born? "); int inputYear = abc.nextInt(); System.out.println("You were born on " + inputMonth + " " + inputDay + "," + " " + inputYear + "." + " You're mighty old!");}所以,再次:获取方法签名以匹配要求(不清楚它是否应该是静态的,因此可能需要是)。public static inputBirthday(Scanner abc)不要在方法中实例化扫描仪。inputBirthday要从 IDE 进行测试,请执行以下操作:public static void main(String[] args) { Scanner in = new Scanner(System.in); // either instantiate the enclosing class, or make inputBirthday static inputBirthday(in);}