Closing a port that is opened is typically not something you can do programmatically from your Java port scanner.
When your port scanner identifies an open port, it means that there is some service or application listening and accepting connections on that port. The ability to close that port generally lies with the application or service that is utilizing it, not with external programs like your port scanner.
If you want to "close" a port in the context of your own program, you typically achieve this by stopping the service or application that is listening on that port. This would effectively close the port because there is no longer a service actively accepting connections on it.
If you are looking to have control over closing ports...