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.
- Does JVM create object of Main class (the class with main())?
- What are the main differences between the Java platform and other platforms?
- Difference between ExecutorService execute() and submit() method in Java
- How to call some function before main() function in C++?
- Java Multicasting (Typecasting multiple times) Puzzle
- Valid variants of main() in Java
- GFact 48 | Overloading main() in Java
- Main thread in Java
- Is main method compulsory in Java?
- Replacing 'public' with 'private' in "main" in Java
- Understanding "static" in "public static void main" in Java
- Static Block and main() method in Java
- Understanding public static void main(String args) in Java
- How to overload and override main method in Java
- In Java, Can we call the main() method of a class from another class?
- How to create a Circular image view in Android without using any library?
- return statement vs exit() in main()
- What does main() return in C and C++?
- Main App Implements Runnable | Concurrent Programming Approach 2
- Check whether two Strings are Anagram of each other using HashMap 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.