Help on JAVA Assignment?

Hi! I was wondering why it keeps showing an error when i try to close the scanner? Before it said I had to close the scanner and now when im trying to it says that is an error. On the error it says "cannot make static reference to the non-static method clsoe() from type Scanner"... so basically how to fix the error ???

Attachment image

1 Answer

  • Anonymous
    4 months ago
    Favorite Answer

    Because you're supposed to do input.close() and not Scanner.close()

    close() is not a static method, so you can't call a non-static method without an instantiated object to call it with.

    When you do Scanner.close() you're not closing anything, because Scanner is just a class.

Still have questions? Get your answers by asking now.