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);
}
}
相关文档:
public static void main(String[] args)
{
Integer[] arrInt = new Integer[6];
arrInt[0] = 123;
arrInt[1] = 3453;
arrInt[2] = 345;
arrInt[3] = 23;
arrInt[4] = 11;
arrInt[5] = 345;
int temp = 0;
for (int i ......
Java串口通讯
串行通讯协议有很多种,像RS232,RS485,RS422,甚至现今流行的USB等都是串行通讯协议。而串行通讯技术的应用无处不在。可能大家见的最多就是电脑的串口与Modem的通讯。记得在PC机刚开始在中国流行起来时(大约是在90年代前五年),那时甚至有人用一条串行线进行两台电脑之间的 ......
JAVA中基本变量共包括:byte,short,int,long,float,double,char,boolean,在程序中用的最普遍,最多,但是它们的一些关键也经常被我们所忽略,我今天总结了一下,贴在这里。。。
1.
变量定义:
一个由标识符定义的数据项,包括类型、名称和值三个部分
2.
变量分类:
类 ......
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.text.AttributedCharacterIterator;
import java.text. ......