简体   繁体   中英

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. 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 .
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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