can you help me to find out the error in this java code?

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.

public static void main(String[] args) {}

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

return final_ans;

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

System.out.println(ans)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top