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

Relevance
  • Anonymous
    2 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.

    • niki2 months agoReport

      just got it! thank you for the help, truly appreciate it

Still have questions? Get your answers by asking now.