我做个菜单选项如下,每次选完之后就跳过去了,没法自动再给出菜单选项,用什么办法能实现返回菜单选项?
import java.util.*;
import java.io.*;
import java.lang.Math;
public class GPS {
public static String readMenu(){
String inPut = " ";
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println( "Now Choose what you want to do: ");
System.out.println( "1: Search for state ");
System.out.println( "2: Search for city ");
System.out.println( "3: Set current city ");
System.out.println( "4: Show current city ");
System.out.println( "5: Find n closest ");
System.out.println( "6: Find shortest path ");
System.out.println( "7: Quit ");
System.out.println( "...................... ");
System.out.println( "Enter the number to choose the menu. ");
inPut = br.readLine();
}
catch(IOException ioe){
System.err.println( "IOException: " + ioe.getMessage());
}
return inPut;
}
public static void main(String[] args) throws IOException{
int menu = 0;
menu = Integer.parseInt(readMenu());
if(menu == 1){
System.out.println( "Now enter the state name, for example: New York ");
stateName = readInput();
searchState(stateName, cityNumInt, cities);
}
if(menu == 2){
System.out.println( "Now enter the city name, for example: New York City ");
cityName = readInput();
searchCity(cityName, cityNumInt, cities);
}
if(menu == 3){
System.out.println( "Now enter the city name, for example: New York City ");
currentCity = readInput();
currentCityID = setCurrentCity(currentCity, cityNumInt, cities);
}
if(menu == 4){
System.out.println( "The current city ID is " + currentCityID);
System.out.println( "name = " + cities[currentCityID].name);