Reputation: 13
I got this problem when running the following code in Java:
public class comparison
{
public static boolean main(String[] args)
{
if (0.1 + 0.1 + 0.1 == 0.3) return true;
else return false;
}
}
Can anybody tell me why and how to modify the code?
Upvotes: 1
Views: 175
Reputation: 96016
main
method should be:
public static void main(String[] args)
and not:
public static boolean main(String[] args)
You probably wanted to do something like this:
public static boolean check()
{
if (0.1 + 0.1 + 0.1 == 0.3) return true;
else return false;
}
and then call it from the static main:
public static void main(String[] args)
{
boolean result = check();
//now you can print, pass it to another method.. etc..
}
Why main is void (doesn't return anything)?
Why main is public?
Why main is static?
Upvotes: 3
Reputation: 4942
To be executable from the commandline, Java classes must implement a static method with signature
public static void main(String[] args) {
Because yours returns "boolean" instead of "void", the JVM doesn't know how to execute it. You'll need to either modify that method, or wrap it in another similar one with return type "void".
Upvotes: 0