2043-Contraseña (java)

Inserte la descripción de la imagen aquí
Idea : escriba la contraseña en forma de cadena y luego use el método charAt para convertirla en una cadena, y luego use el bucle for para recorrer la comparación if. El siguiente es el código ASCLL.
Inserte la descripción de la imagen aquí

import java.util.*;
public class Main {
    
    
public static void main(String[] args) {
    
    
	Scanner a=new Scanner(System.in);
	int M=a.nextInt();
	a.nextLine();
	while(a.hasNext())
	{
    
    
		String str=a.nextLine();
		if(str.length()<=50)                                             //字符长度限定
		{
    
    
		int sum=0,num=0,bum=0,mum=0,h=0;								 //计数器
		for(int i=0;i<str.length();i++)									 //对字符串的的每一位字符进行判断和计数
		{
    
    
			if(str.charAt(i)>='a'&&str.charAt(i)<='z')
				sum=1;
			else if(str.charAt(i)>='A'&&str.charAt(i)<='Z')
				num=1;
			else if(str.charAt(i)>='0'&&str.charAt(i)<='9')
				bum=1;
			else if(str.charAt(i)=='~'||str.charAt(i)=='!'||str.charAt(i)=='@'||str.charAt(i)=='#'||str.charAt(i)=='$'||str.charAt(i)=='%'||str.charAt(i)=='^')
				mum=1;                                                   //对特殊字符需要注意使用||而不是&&
			else
			{
    
    
				h++;
				break;
			}
		}
		if(h!=0)
		{
    
    
			System.out.println("NO");
			break;
		}
		if((str.length()>=8&&str.length()<=16)&&sum+num+bum+mum>=3)		//密码的两个要求
			System.out.println("YES");
		else
			System.out.println("NO");
	  }
		else
			System.out.println("NO");
	}
}
}

Si hay un error, corríjalo;

Supongo que te gusta

Origin blog.csdn.net/weixin_45956604/article/details/114733367
Recomendado
Clasificación