How do I use != in java strings [closed]

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How do I use != in java strings [closed]



My code has a validator which states that if "d" is entered display an error message. If "c", "s", or "v" are entered do the calculation. How can I construct gender.equalsIgonreCase to include all words and letters that are not "c", "s", or "v"?


gender.equalsIgonreCase



Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





All ASCII letters but c, s, v? gender.matches("(?i)[a-z&&[^csv]]")?
– Wiktor Stribiżew
Sep 22 '16 at 21:18




c


s


v


gender.matches("(?i)[a-z&&[^csv]]")





Your question is very unclear, due to including all kinds of extra (and repeated) code which appears to be completely irrelevant. Please provide a Minimal, Complete, and Verifiable example.
– Jon Skeet
Sep 22 '16 at 21:20





I am just trying to bring up a error message if c or v or s are not entered.
– dd cece
Sep 22 '16 at 21:26





Are you expecting gender to be equal to "d" and ("s", "v" or "c") even if you ignore the case??? You could instead just write boolean genderCheck1 = false, genderCheck2 = false, genderCheck3 = false;.
– fabian
Sep 22 '16 at 22:05




gender


"d"


"s"


"v"


"c"


boolean genderCheck1 = false, genderCheck2 = false, genderCheck3 = false;




3 Answers
3



You could use String.matches(String) which takes a regular expression to validate gender. Like


String.matches(String)


gender


boolean isCSV = gender.matches("[CcSsVv]");
if (!isCSV) {
// It isn't C, c, S, s, V or v
}





Am I supposed to add the error message where the comment is currently or the calculations?
– dd cece
Sep 22 '16 at 21:24





@MosVIN Put what you want to happen when the gender isn't one of C, c, S, s, V or v. Add an else for when it is. Or remove the ! and swap the cases.
– Elliott Frisch
Sep 22 '16 at 21:50


gender


else


!





your right it worked!. How could I do something similar for say if a number is not equal to 10. Only not have a error message come up unless i enter 10
– dd cece
Sep 22 '16 at 22:57



You probably would be better going with the String.matches(String) option as mentioned above by @Elliott Frisch but just some constructive criticism, you should look up a couple of java tutorials thenewboston youtube channel has tons of very good tutorials.



If your going to learn Java you should really try learn all the basic stuff you could save yourself so many headaches in the future as you'd have a better idea of what you can use to solve your problems ..



all the String methods() ect ..



you can use "else" :


if(gender.equals("C")){
....
}
else if(gender.equals("S")){
....
}
else{
.....
}



or you can use !gender.equals("d"):


!gender.equals("d")


if(!gender.equals("d")){
.....
}

R CQGwjkuVbg9e D,5siNL6sHS0LHTV6,UZyK tqNvqUb5TjhTrhEg88R2B0 pybL48RRG7ZCLvSg Xs1QC DZy,H7qOcyEtwKl759
t8govvb1r,j,az,yDlkK4q39Ffmi0,c68TT4aaJEKVOXOsKvcuDcVmbiEby,A47,xDsylSVh54wMUd4JmpX EOZf7l5PAoesRF4,RKQcs Y

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham