java - sorting by first character -


the question @ hand each policy no. string of 9 characters of indicates type of insurance policy

  • b building policy
  • c contents policy
  • l life policy
  • v car policy

each of remaining 8 characters of policy number decimal digit.

i have tried using charat told me there better way

public string getpolicyno(string initpolicyno) {      /**      * access method find first character of policy      * determine type of policy is.      */     string b = "b";     string c = "c";     string l = "l";     string v = "v";      char c1 = b.charat(0);     char c2 = c.charat(0);     char c3 = l.charat(0);     char c4 = v.charat(0);       if (c1 == 0) {         system.out.println("its building" + c1);         return initpolicyno;     } else {         if (c2 == 0) {             system.out.println("its content");             return initpolicyno;         } else {             if (c3 == 0) {                 system.out.println("its life");                 return initpolicyno;             } else {                 if (c4 == 0) {                     system.out.println("its car");                      return initpolicyno;                 }             }         }     }     throw new illegalargumentexception(); } 

i'm not looking provide answer me, i'm looking possible alternatives , possible suggestions.

many thanks

dan

i'm not sure trying achieve, write way:

public string getpolicyno(string initpolicyno) {     switch(initpolicyno.charat(0))     {        case 'b':           system.out.println("its building b");           return initpolicyno;        case 'c':           system.out.println("its building c");           return initpolicyno;        case 'l':           system.out.println("its building l");           return initpolicyno;        case 'v':           system.out.println("its building v");           return initpolicyno;     }      throw new illegalargumentexception(); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -