简体   繁体   English

编译错误

[英]Compiling Error

The accompanying code is inadequately organized.随附的代码组织不充分。 Rework it with the goal that it has a finer structure and keeps away from excess.重新设计它的目标是它具有更精细的结构并避免过量。 To help wipe out excess, change over the code into a strategy named using that acknowledges two parameters: a Scanner for the comfort, and a String for a solitary individual's name, and prints the suitable data about that individual's bills.为了帮助消除多余的部分,将代码更改为一个名为 using 的策略,该策略承认两个参数:一个用于舒适度的扫描器,一个用于单独个人姓名的字符串,并打印有关该个人账单的合适数据。 Your technique could be called twice (once for John and once for Jane) to duplicate the first code's conduct.你的技术可以被调用两次(一次给约翰,一次给简)来复制第一个代码的行为。

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;
}

Error错误

Return types do not match.
expected return type: void
your return type was: int

I think the error message is pretty clear.我认为错误信息很清楚。 The validator expects your helper method to not return anything (have void return type), but your method returns int .验证器希望您的辅助方法不返回任何内容(具有void返回类型),但您的方法返回int
The instructions do say that the helper method should do the printing, so just move that code into the spending method, change the return type, and you should be fine.说明确实说辅助方法应该进行打印,因此只需将该代码移动到spending方法中,更改返回类型,就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM