So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement. Unfortunately, i do not know how. Please, rather than just give me an example of random code; could you please adapt my example (even if only by a couple of lines), that way, it is much easier for me to understand as i already grasp the concept of this method that i am using.
public String checkPasswordStrength(String passw) { int strengthCount=0; String strengthWord = ""; String[] partialRegexChecks = { ".*[a-z]+.*", // lower ".*[A-Z]+.*", // upper ".*[\\d]+.*", // digits ".*[@#$%!]+.*" // symbols }; if (passw.matches(partialRegexChecks[0])) { strengthCount+=1; } if (passw.matches(partialRegexChecks[1])) { strengthCount+=1; } if (passw.matches(partialRegexChecks[2])) { strengthCount+=1; } if (passw.matches(partialRegexChecks[3])) { strengthCount+=1; } if (passw.length()>7) { strengthCount+=1; } //StrengthCount Converted to string if (strengthCount==0) { strengthWord = "No password; da fuq hacks"; } if (strengthCount==1) { strengthWord = "Very Weak"; } if (strengthCount==2) { strengthWord = "Weak"; } if (strengthCount==3) { strengthWord = "Medium"; } if (strengthCount==4) { strengthWord = "Strong"; } if (strengthCount==5) { strengthWord = "Very Strong"; } return strengthWord; }
Please help me!