java - Make Main Method restart/refresh -
my code far:
import java.util.*; import java.util.scanner.*; public class project{ // main method public static void main(string [] args){ // creates main method system.out.println("name method (stability, efficiency ..)"); // asks user select method scanner scan = new scanner(system.in); // creates scanner string splash = scan.nextline(); // transitions user next line after choosing method if(splash.equals("efficiency")) // if users chooses efficiency goes efficiency method { efficiency(); // calls efficiency method } if(splash.equals("stability")) // if user chooses stability goes stability method { stable(); // calls stability method } else // happens if input wasnt recognized { system.out.println("i don't recognize this"); // happens if irrelevant method chosen } } }
how make instead of:
else // happens if input wasnt recognized { system.out.println("i don't recognize this"); // happens if irrelevant method chosen }
it refresh or restart main method?
wrap code in while
loop leave when user chooses exit command:
public static void main(string [] args){ while (true) { system.out.println("name method (stability, efficiency ..)"); scanner scan = new scanner(system.in); string splash = scan.nextline(); if (splash.equals("exit")) { break; } // else if (splash.equals("efficiency")) ... } }
Comments
Post a Comment