Java Code Example for Even Number
Java Code Example for Even Number
even number
import java.util.Scanner; // Import Scanner for user input
o Scanner: The Scanner class is used to take user input from the console.
o Close Scanner: After using the scanner, it’s good practice to close it to avoid resource leaks.
• The statement public static void main(String[] args) is the entry point of any Java application. Let's break down what each part
means:
• public
Visibility Modifier: public is an access modifier. It means that this method can be accessed from anywhere, meaning there are
no restrictions on who can call this method.
In simple terms, public ensures that the main method can be accessed by the Java runtime to start your program.
• static
Static Keyword: static means that this method belongs to the class, not to any specific instance of the class.
The Java runtime can call this method without creating an instance (object) of the class. It makes it accessible directly through
the class.
Since main is static, it can be invoked without creating an object of the class.
• 3. void
Return Type: void means that this method does not return any value. The main method is simply used to start the program,
• main
Method Name: main is the name of the method. This is a special method name in Java that the Java Virtual
Machine (JVM) looks for when you run your program.
The JVM starts execution from the main method in your program.
• 5. String[] args
• args is a name commonly used to represent command-line arguments that you pass when running the
program. These are typically input values that the user provides when executing the program from the
command line or terminal