1、编译失败时,注释报错代码,一点点调试;注意结尾分号,方法名的正确性,联想不出方法时,试试刷新页面后重新联想
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
if(str.length()<8){
System.out.println("NG");
continue;
}else if(getStr(str,0,3)){
System.out.println("NG");
continue;
}else if(test2(str)){
System.out.println("NG");
continue;
}else{
System.out.println("OK");
}
}
}
//检查重复字符串
public static boolean getStr(String str,int i,int j){
if(j>=str.length()){
return false;
}
if(str.substring(j).contains(str.substring(i,j))){
return true;
}else{
return getStr(str,i+1,j+1);
}
}
//检查长度以及字符串种类
public static boolean test2(String str){
int count=0;
Pattern p1=Pattern.compile("[A-Z]");
if(p1.matcher(str).find()){
count++;
}
Pattern p2=Pattern.compile("[0-9]");
if(p2.matcher(str).find()){
count++;
}
Pattern p3=Pattern.compile("[a-z]");
if(p3.matcher(str).find()){
count++;
}
Pattern p4=Pattern.compile("[^a-zA-Z0-9]");
if(p4.matcher(str).find()){
count++;
}
if(count<3){
return true;
}else{
return false;
}
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
if(str.length()<8){
System.out.println("NG");
continue;
}else if(getStr(str,0,3)){
System.out.println("NG");
continue;
}else if(test2(str)){
System.out.println("NG");
continue;
}else{
System.out.println("OK");
}
}
}
//检查重复字符串
public static boolean getStr(String str,int i,int j){
if(j>=str.length()){
return false;
}
if(str.substring(j).contains(str.substring(i,j))){
return true;
}else{
return getStr(str,i+1,j+1);
}
}
//检查长度以及字符串种类
public static boolean test2(String str){
int count=0;
Pattern p1=Pattern.compile("[A-Z]");
if(p1.matcher(str).find()){
count++;
}
Pattern p2=Pattern.compile("[0-9]");
if(p2.matcher(str).find()){
count++;
}
Pattern p3=Pattern.compile("[a-z]");
if(p3.matcher(str).find()){
count++;
}
Pattern p4=Pattern.compile("[^a-zA-Z0-9]");
if(p4.matcher(str).find()){
count++;
}
if(count<3){
return true;
}else{
return false;
}
}
}