Skip to content
Advertisement

Can you help me to find out the error in this Java Code

JavaScript

Giving error as Void methods cannot return a value. If am trying to change the method as static and removing void it’s not running as java application.

Advertisement

Answer

main is void, so it should not return anything, you cannot have a return statement in the main method.

Every method must contain a return type ( example int, long, double, int[] , and void where void means the method will not return anything).
if you try to run a method without a return type then it will not run.

JavaScript

this method’s return type is void, it means there should not be a return statement inside this method
but you are returning the ans in the end

JavaScript

therefore, to run the application you need to remove the return statement and instead you can print the answer to the console like this

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement