i wonder if there more elegant way write if statement lot of || in java. i've given different values alphabet letters:
a,o,i,b,t,s,m,n -> 1 c,d,f,g -> 5 w,y,z,h,q -> 10
so, want check given letter , if equal 1 of 2nd group example 5. right i'm checking this:
string value; if (getletter().equals("Α")|| getletter().equals("o") || getletter().equals("i") || getletter().equals("b") || getletter().equals("t") || getletter().equals("s") || getletter().equals("n") || getletter().equals("n")) value = "1";
is there better way it?
string letter = getletter(); if ("aoibtsmn".contains(letter)) value = "1"; else if ("cdfg".contains(letter)) value = "5"; else if ("wyzhq".contains(letter)) value = "10";
not optimal, short, clear , self-explaining.
Comments
Post a Comment