2013-05-08 74 views
0

我迄今爲止代碼:使主要方法重啓/刷新

import java.util.*; 
import java.util.Scanner.*; 

public class Project{ // The Main Method 
    public static void main(String [] args){ // Creates the Main Method 
    System.out.println("Name a Method (Stability, efficiency ..)"); // Asks the user to select a method 
    Scanner scan = new Scanner(System.in); // Creates the Scanner 
    String splash = scan.nextLine(); // Transitions the user to the next line after choosing a method 
    if(splash.equals("efficiency")) // If users chooses Efficiency then it goes to the Efficiency method 
    { 
     efficiency(); // Calls the Efficiency method 
    } 
    if(splash.equals("Stability")) // If user chooses Stability then it goes to the Stability Method 
    { 
     stable(); // Calls the Stability method 
    } 
     else // What happens if the input wasnt recognized 

    { 
     System.out.println("I don't recognize this"); // what happens if an irrelevant method is chosen 
    } 
    } 
} 

我將如何讓這個代替:

else // What happens if the input wasnt recognized 
{ 
    System.out.println("I don't recognize this"); // what happens if an irrelevant method is chosen 
} 

這將刷新或重新啓動的主要方法是什麼?

回答

3

包裝你的代碼在while循環,你離開的時候,用戶選擇退出命令:

public static void main(String [] args){ 

    while (true) { 
     System.out.println("Name a Method (Stability, efficiency ..)"); 
     Scanner scan = new Scanner(System.in); 
     String splash = scan.nextLine(); 
     if (splash.equals("exit")) { 
      break; 
     } // else if (splash.equals("efficiency")) ... 
    } 

} 
+0

你能也許把它與正確的括號內的主要方法是什麼?我越來越混合括號 – 2013-05-08 13:30:20

+0

@ user2335970:像這樣? – Kai 2013-05-08 13:32:00

+0

謝謝你!〜!! – 2013-05-09 13:11:45