{
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);
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务