編寫一個名爲的方法,該方法接受控制檯的掃描儀作爲參數,並提示用戶輸入出生月份,日期和年份,然後以合適的格式打印出生日。下面是與用戶的例子對話:Java初學者 - 使用參數和掃描儀
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();
}
我的代碼無法編譯。有人可以給我一些提示,我會自己嘗試一下。
提示?仔細閱讀編譯錯誤 - 它會告訴你它發生的文件和行號以及問題是什麼。 – duffymo 2013-02-10 17:08:40
你的錯誤是什麼?假設你將它包裝在一個類中,它對我來說編譯得很好。 – MrHappyAsthma 2013-02-10 17:09:18
錯誤是用import java.util.Scanner; – user2059072 2013-02-10 17:10:45