java - Creating a sub menu using String/char? -


public static string getsubmenu(string submenu){         scanner keyboard = new scanner(system.in);         string chosen="", a="a",b="b", a="a", b="b";         do{         chosen = keyboard.next();         keyboard.nextline();         system.out.print("\n\n");         }while(chosen.compareto(a));         return chosen;     }     //this function below fine.     public static void menu(){         string unem="";         do{         system.out.println("sub menu");         system.out.println("select option\n\n");         system.out.println("a.sort name\n" +                                                        "b.sort time\n" +                            "c.exit sub-menu\n\n");         system.out.print("input number selected option: ");         unem= getsubmenu(unem);         if("a".equals(unem)|| "a".equals(unem)){          }         if("b".equals(unem)|| "b".equals(unem)){          }     }while ("a".equals(unem) ||"b".equals(unem) || "a".equals(unem) || "b".equals(unem));      }  } 

hi, i'm trying make sub menu. can see in function menu, when getsubmenu called user has input selected option in function getsubmenu. looked through textbook , online , doesn't seem can use char within arguments such

char a="a"; if(a != b);  

if can use characters instead of strings in functions above please tell.

but moving on. trying getsubmenu return string containing either 'a' || 'a' || 'b' || 'b' || 'c' || 'c' , loop when user not put of these input. i've tried attempting use compareto receive type mismatch: cannot convert int boolean error how can improve on this. syntax can use can work.

thanks , contribute this.

edited: new working function

  public static string getsubmenu(string submenu){             scanner keyboard = new scanner(system.in);             boolean looped = true;             string chosen="";             do{             chosen = keyboard.next();             keyboard.nextline();             system.out.print("\n\n");             if("a".equals(option)|| "a".equals(option) || "b".equals(option)|| "b".equals(option) || "c".equals(option)|| "c".equals(option)){                 looped = false;             }             else                 system.out.println("wrong input");             }while(looped);             return option; 

it may of not been aiming still did job.

while(chosen.compareto(a)) should error . method compareto(string) returns int cannot use in while(boolean expression) , requires boolean expression shall evaluate true or false. pasting code reference , improvise on :

 public static string getsubmenu(string submenu) {     scanner keyboard = new scanner(system.in);     list<string> list = arrays.aslist(new string[]{"a","b","c"});     {         chosen = keyboard.next();         keyboard.nextline();         system.out.print("\n\n");     } while (chosen!=null && list.contains(chosen.touppercase()));     return chosen; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -