当前位置: 技术问答>java相关
如何用java实现递归?给n个整数,写出计算结果为24的算法,要所有数都用上,只用加减乘除实现
来源: 互联网 发布时间:2015-08-27
本文导语: 如何用java实现递归?给n个整数,写出计算结果为24的算法,要所有数都用上,只用加减乘除实现 .如果java类中方法之间需要调用,参数的传递如何实现? | 小菜一蝶,注:除法使用四舍五入,如果和...
如何用java实现递归?给n个整数,写出计算结果为24的算法,要所有数都用上,只用加减乘除实现 .如果java类中方法之间需要调用,参数的传递如何实现?
|
小菜一蝶,注:除法使用四舍五入,如果和你要求的不一样,改Math.round为其他函数即可
/* By Daniel Woo you can contact me: DanielYWoo.hotmail.com*/
import java.util.Random;
public class NumPuzzle{
private int n=6;
private int MAX = 100;
private int num[] = new int[n];
Random rand = new Random();
public static final int OP_PLUS = 1;
public static final int OP_MINUS = 2;
public static final int OP_MULTI = 3;
public static final int OP_DIVIDE = 4;
public static void main(String args[])
{
NumPuzzle np = new NumPuzzle();
np.init();
np.resolve(0, 0, 0);
}
public void init()
{
int i;
for(i=0; i
/* By Daniel Woo you can contact me: DanielYWoo.hotmail.com*/
import java.util.Random;
public class NumPuzzle{
private int n=6;
private int MAX = 100;
private int num[] = new int[n];
Random rand = new Random();
public static final int OP_PLUS = 1;
public static final int OP_MINUS = 2;
public static final int OP_MULTI = 3;
public static final int OP_DIVIDE = 4;
public static void main(String args[])
{
NumPuzzle np = new NumPuzzle();
np.init();
np.resolve(0, 0, 0);
}
public void init()
{
int i;
for(i=0; i