I have problem with infinite recursion. Main method will run, then if I chose 1, it will go to submenu(). But, when I choose a wrong option in submenu(), the program must be loop back to main method.
However, this situation can result stack overflow.
Do you have any ideas guys related to this problem? How could the it loop back to main method without calling the main()?
Thanks a lot guys.
public void main() {
// variables omitted
while (menu) {
switch (option) {
case 1:
subMenu();
break;
}
}
}
public void subMenu() {
switch (a) {
case 1:
case 2:
default:
System.out.println("Invalid Option");
main();
}
}