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 Abdukhalilov5 Answers
New AnswerThat'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. https://code.sololearn.com/cKFzVN71C8Py/?ref=app
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.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message