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

+2

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

+13

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); } }

+7

You can do this with a for-loop if its just the variables you want to reset. https://code.sololearn.com/cKFzVN71C8Py/?ref=app

+6

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.

+3

Put while True in main

+2

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