{
a[i]=scanner.nextInt();
}
Arrays.sort(a);
//对数组a的元素进行排序
//
System.out.print("排序后:");
for(int i:a)
//用i接收数组a的元素输出
{
System.out.print(i+" ");
}
}
}
package one;
import java.util.Scanner;
public class Example3_4 {
private int c=0;
public void hanoi(int n,char x,char y,char z){
if(n==0){
System.out.println("退出程序!!!");
System.exit(0);
}
if(n==1){
move(x,1,z);
}
else{
hanoi(n-1,x,z,y);
move(x,n,z);
hanoi(n-1,y,x,z);
}
}
private void move(char x, int n, char z) {
// TODO 自动生成的方法存根
System.out.println("第"+ ++c+"次移动:"+n+"号圆盘,"+x+"->"+z);
}
public static void main(String[] args){
Example3_4 h=new Example3_4();
do{
Scanner reader=new Scanner(System.in);
System.out.print("请输入圆盘的个数n:");
int n=reader.nextInt();
h.hanoi(n,'x','y','z');
System.out.println();
}while(true);
}
}