//-----------------------------------------------------
JPanel ContentPane;
JLabel JLabel1 = new JLabel ();
JLabel JLabel2 = new JLabel ();
JTextField jTextField2 = new JTextField ();
JTextField jTextField1 = new JTextField ();
JButton jButton1 = new JButton ();
JButton jButton2 = new JButton ();
JTextField jTextField3 = new JTextField ();
JLabel jLabel3 = new JLabel ();
----------------------N!------------------------------
public int function (int N) {
if (n==1)
return 1;
else{
Return n*function (N-1);
/* is not a return function (N-1);
But N*function (N-1);
}
}
-----------a recursive method for the whole arrangement of a string-----------------------
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;
/* No return in If? */
}
------------------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);
/* method. parseint is converted to int type
And not. 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");
}
}
----------out put result 2---------------------
public void OutPutRestlt2 () {
Index=0;//let index come back to 0
String Strlength, Strmoshu,
Aimstring, Prefix,suffix;
int Length, Moshu,limit;
Strlength = Jtextfield2.gettext ();
Strmoshu = Jtextfield3.gettext ();
Length = Integer.parseint (strlength);
Moshu = Integer.parseint (Strmoshu);
Limit = function (Length);
int[] Eacharrange = new Int[this.function (Length)];
if (Length > 2&&length<9&&
strlength!= "" &&strmoshu!= ""
&&moshu<limit) {
prefix = "";
Suffix =creatstring (Length);
Arrange (prefix, suffix, eacharrange);
Arrays.sort (Eacharrange);
String strresult=string.valueof (Eacharrange[moshu]);
Jtextfield1.settext (strresult);
}
Else
System.out.println ("Input Ouf Moshu, Try again");
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.