您已经说过您只需要一个近似解决方案(80% 的准确度),可能是 AClassName 形式的类(注意大写),并且给定的加密文本样本中没有大写字母。所以
public class Test{
public static void main(String args[]){
String[] tests=new String[5];
tests[0]="MyClass";
tests[1]="Short";
tests[2]="thsrjtyzfgnmytkzrhjstk";
tests[3]="tatm";
tests[4]="The result is good";
for(int i=0;i<tests.length;i++){
System.out.println(tests[i]+ "- Encrypted:" + isProbablyEncrypted(tests[i]));
}
}
public static boolean isProbablyEncrypted(String in){
int noOfWords= countOccurrences(in, ' ') + countCaps(in);
if (noOfWords==0){
return true;
}else{
double averageWordLength=(double)(in.length())/(noOfWords+1);
if (averageWordLength>15){
return true;
}else{
return false;
}
}
}
public static int countOccurrences(String haystack, char needle)
{
int count = 0;
for (int i=0; i < haystack.length(); i++)
{
if (haystack.charAt(i) == needle)
{
count++;
}
}
return count;
}
public static int countCaps(String in){
int caps=0;
for (int i=0; i<in.length(); i++) {
if (Character.isUpperCase(in.charAt(i)))caps++;
}
return caps;
}
}
这是一个好的解决方案吗?不,它是否提供> 80%的准确度?是的