The error tell evething. either you forget to declare main method
or somthing missing in main method declaration
. In Java Programming The main()
method is a special method that serves as the externally exposed entrance point by which a Java program can be run. To compile a Java program, you doesn't really need a main()
method in your program. But, while execution JVM searches for the main()
method and starts executing from it.
You declare int argument in main method but it shoud be String[] args
. now one question arise in your mind Why String args[]?
because When you run a Java program from a command line, you are allowed to pass data into that program as comnand line arguments
.Your Java program will run from a main()
method, and the arguments you typed on the command line will appear to the Java program as Strings in that array.
Here down is right syntex:
public static void main(String[] args) {
// Some code inside main function....
}
And your code should be:
public class Main {
static void printSomeNumber()
{
int a = 10;
int b = 20;
System.out.printf("%d %d", a, b);
}
public static void main(String args[]) {
printSomeNumber();
}
}