当前位置: 代码迷 >> J2SE >> 怎么给出选项,选完之后再返回选项菜单,继续让用户选择?不用GUI
  详细解决方案

怎么给出选项,选完之后再返回选项菜单,继续让用户选择?不用GUI

热度:165   发布时间:2016-04-24 15:49:28.0
如何给出选项,选完之后再返回选项菜单,继续让用户选择?不用GUI
我做个菜单选项如下,每次选完之后就跳过去了,没法自动再给出菜单选项,用什么办法能实现返回菜单选项?  

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);
  相关解决方案