JAVA加密解密算法研究 第7页

JAVA加密解密算法
/*不是RETURN function(N-1);
而是 N*function(N-1);*/
}
}
//-----------用递归法求一个串的全排列-----------------------
public void Arrange(String prefix,String suffix,int[] Array){
String newPrefix,newSuffix;
int numOfChars =suffix.length();
if(numOfChars==1){
Array[index]=Integer.parseInt(prefix+suffix);
index++;
}
else{
for(int i=1; i<=numOfChars;i++){
newSuffix=suffix.substring(1,numOfChars);
newPrefix=prefix+suffix.charAt(0);
Arrange(newPrefix,newSuffix,Array);
suffix=newSuffix+suffix.charAt(0);
}
}
}
//----------Arrange From the Min to the Max------------------
/*public void RankForArrange(int[] Array){
int bottom=Array.length-1 ;
int temp;
for(int i=bottom;i>0;i--){
for(int j=0;j<i;j++){
if(Array[j]>Array[j+1]){
temp =Array[j];
Array[j] =Array[j+1];
Array[j+1]=temp;
}
}
}
}
*/
//-------------------Find the aim number----------------------
public int FindAim(int aim,int[] Array){
boolean isFound=false;
int location=0;
int length=Array.length ;
for(int i=0;i<length;i++){
if(Array[i]==aim){
location=i;
isFound =true;
}
}
if(isFound)
return location;
else
System.out.println("Not Found");
return location;
/*在if里return 不行吗?*/
}

//------------------Creat String-------------------------------
public String CreatString(int length){
StringBuffer BufString=new StringBuffer();
for(int i=1;i<=length;i++){
BufString.append(i) ;
}
return BufString.toString();
}
//-----------OutPut Result--------------------
public void OutPutResult1(){
index = 0; //clear to 0
String AimString, prefix;
AimString = jTextField1.getText();
int Length = AimString.length();
String strLength = String.valueOf(Length);
int Aim = Integer.parseInt(AimString);
/* 方法.parseInt才是转换为int类型
而不是.getInteger*/
int[] EachArrange = new int[this.function(Length)];
jTextField2.setText(strLength);
prefix = ""; //Make an empty String
if (AimString.length() > 2 &&
AimString.length() < 9 && AimString != "") {
Arrange(prefix, AimString, EachArrange);
//RankForArrange(EachArrange);
Arrays.sort(EachArrange);
String result = String.valueOf(FindAim(Aim, EachArrange));
jTextField3.setText(result);
}
else {
System.out.println("Your String is too short");
}
}

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有