JAVA密碼處理,主要是字串對比處理
阿新 • • 發佈:2018-12-19
在後臺經常會遇到的密碼處理,寫一個部落格記錄一下,主要是用到了String.matches的字串對比
//密碼處理 import java.util.Scanner; public class Practice1162 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int hang = sc.nextInt(); for (int i = 0; i < hang; i++) { String password = sc.next(); int safelevel = 0; //安全級別 int length = password.length(); if ( length > 16 || length < 8) System.out.println("NO"); else { int moshi = 0; if (password.matches("(.*)[A-Z](.*)")) { //字串中有A-Z safelevel++; } if (password.matches("(.*)[a-z](.*)")) { //字串中a-z safelevel++; } if (password.matches("(.*)[0-9](.*)")) { //字串中含有0-9 safelevel++; } if (password.matches("(.*)[
[email protected]#$%^](.*)")) { //字串含有[email protected]#$%^ safelevel++; } if (safelevel >= 3) { System.out.println("YES"); } else { System.out.println("NO"); } } } } }