+ 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

5th Apr 2019, 4:12 PM
Sanjarbek Abdukhalilov
Sanjarbek Abdukhalilov - avatar
5 Respuestas
+ 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); } }
5th Apr 2019, 5:02 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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
5th Apr 2019, 8:59 PM
D_Stark
D_Stark - avatar
+ 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.
5th Apr 2019, 5:25 PM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
+ 3
Put while True in main
5th Apr 2019, 4:58 PM
Elva
Elva - avatar
+ 2
in example above call main(args); (str) is not necesary
5th Apr 2019, 8:34 PM
zemiak