-5
隨附的代碼組織不當。重做它的目標是它有一個更精細的結構,並遠離過度。爲了幫助消除過量,將代碼轉換爲名爲using的策略,確認兩個參數:掃描儀以獲取舒適感,以及單獨個人姓名的字符串,並打印有關該人賬單的合適數據。你的技巧可以被調用兩次(一次是約翰和一次是簡),以複製第一個代碼的行爲。編譯錯誤
public static void main (String [] args) {
Scanner console = new Scanner(System.in);
int numBills1 = spending(console, "John");
int numBills2 = spending(console, "Jane");
System.out.println("John needs " + numBills1 + " bills");
System.out.println("Jane needs " + numBills2 + " bills");
}
public static int spending(Scanner console, String name) {
System.out.print("How much will " + name + " be spending? ");
double amount = console.nextDouble()
System.out.println();
int numBills = (int) (amount / 20.0);
if (numBills * 20.0 < amount) {
numBills++;
}
return numBills;
}
錯誤
Return types do not match.
expected return type: void
your return type was: int
你的問題是什麼?看起來你剛剛發佈了作業問題。 – Barmar
那我提交我的程序時得到的錯誤我想知道爲什麼 – user3552378
你似乎在'double amount ='行中缺少一個分號。 – Barmar