java递归实现汉诺塔
/*
* 汉诺塔,从第1个柱子借助第2根柱子移动到第3根
*/
public class TowerOfHano {
private int totle;//总共盘子数目
public TowerOfHano(int totle){
this.totle=totle;
}
private void moveOne(int start,int end){
System.out.println("从"+start+"移动一块盘子到"+end);
}
private void moveAll(int totle,int start,int temp,int end){
if(totle==1){
moveOne(start,end);
}else{
moveAll(totle-1,start,end,temp);
moveOne(start,end);
moveAll(totle-1,temp,start,end);
}
}
public static void main(String[] args) {
TowerOfHano tower = new TowerOfHano(3);//测试三块盘子
tower.moveAll(tower.totle, 1, 2, 3);
}
}
相关文档:
一些java类中为什么需要重载 serialVersionUID 属性。
在Java中,软件的兼容性是一个大问题,尤其在使用到对象串行性的时候,那么在某一个对象已经被串行化了,可是这个对象又被修改后重新部署了,那么在这种情况下, 用老软件来读取新文件格式虽然不是什么难事,但是有可能丢失一些信息。
serialVersionUID 来解决这些� ......
this的用法在java中大体可以分为3种:
//1.普通的直接引用
class test {
private int x,y;
public test(int x,int y) {
setX(x);//也可以写为this.setX(x);这种情况下this可以省略.
}
}
//2.方法中的某个形参名与当前对象的� ......
public class Migong {
private int gard[][]={ {1,1,1,1,0,1,1,1},
{0,0,0,1,1,1,1,1},
......
//初学JAVA 开发了一个 学生管理程序,拿出来晒晒,以便大家参考或评论 指出不足之处!谢谢 由于此处不能上传照片,故放在我的相
//册里面
//这个登入界面的程序:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
impor ......
Java串口通讯
串行通讯协议有很多种,像RS232,RS485,RS422,甚至现今流行的USB等都是串行通讯协议。而串行通讯技术的应用无处不在。可能大家见的最多就是电脑的串口与Modem的通讯。记得在PC机刚开始在中国流行起来时(大约是在90年代前五年),那时甚至有人用一条串行线进行两台电脑之间的数 ......