Java restart from the beginning | Sololearn: Learn to code for FREE!


Java restart from the beginning

Hi, in java how can I restart my main method when I complete it like a cycle. Do you have any idea? Thanks

4/5/2019 4:12:29 PM

Sanjarbek Abdukhalilov

5 Answers

New Answer


That's how I managed to do that public class Program { static int counter = 10; public static void main(String[] args) { String[] str = null; if(counter == 0) return; counter -= 1; System.out.println("Main called\nCounter: " + counter + "\n"); main(str); } }


You can do this with a for-loop if its just the variables you want to reset.


Classname.main() can be used to access the same method which is main. Its a static method, so Classname vr = new Classname(); vr.main(); Need not be done.


Put while True in main


in example above call main(args); (str) is not necesary