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);
}
}
相关文档:
在一个项目中,客户用C#实现了DES加密,由于需要和java方面的程序进行数据交互,所以必须配合进行加解密工作。客户提供了密钥和向量,我看了看代码,c#做这个事情还蛮简单。 用java实现关键是我不字段怎么设置向量,一般用Cipher对象都是默认随机向量。搞了一阵,发现是用IvParameterSpec这个类来设置。于是有了以下代 ......
最近论坛上看到好几个朋友都在问,如何学习 Java的问题,”我已经学习了J2SE,怎么样才能转向J2EE?”, “我看完了Thinking in Java, 可以学习J2EE了么?”.于是就有了写这篇文章的想法,希望能帮助初学者少走一些弯路。也算是对自己几年来学习Java的一个总结吧.
在开始之前有必要再讨论一下J2ME, ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
Java串口通讯
串行通讯协议有很多种,像RS232,RS485,RS422,甚至现今流行的USB等都是串行通讯协议。而串行通讯技术的应用无处不在。可能大家见的最多就是电脑的串口与Modem的通讯。记得在PC机刚开始在中国流行起来时(大约是在90年代前五年),那时甚至有人用一条串行线进行两台电脑之间的数 ......
一、java访问中文Oracle数据库上连接的US7ASCII数据库
1、读方法
public String convertLink_DB(String s) {
if(s != null){
try{
byte[] b = s.getBytes();
for(int i=0; i<b.length; i++){
b[i] ......