Given task is to execute main() multiple times without using any other function and without recursion() and without error. Given condition is that if executing main() n times then you can only call him (n-1) times.
Explanation: Static block is executed even before the main() executed. Here first, main() get called by static block and then JVM(Java Virtual Machine) call the main(). So, main() is executed two times by calling only one time.
- Java Multicasting (Typecasting multiple times) Puzzle
- Main thread in Java
- Is main method compulsory in Java?
- Valid variants of main() in Java
- GFact 48 | Overloading main() in Java
- Replacing 'public' with 'private' in "main" in Java
- Static Block and main() method in Java
- How to overload and override main method in Java
- What are the main differences between the Java platform and other platforms?
- Understanding public static void main(String args) in Java
- Does JVM create object of Main class (the class with main())?
- Understanding "static" in "public static void main" in Java
- Recursion in Java
- Java and Multiple Inheritance
- Returning Multiple values in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.