If you are using InetlliJ Idea do this setting:
Go to the File menu -> [Settings] -> [Build, Execution, Deployment] -> [Java Compiler] and select your JDK version and sometimes this is empty so insert the java version like [if you use 11] and save,
Then compile the program and run.