Topic: 俄罗斯方快

  Print this page

1.俄罗斯方快 Copy to clipboard
Posted by: tuntun_wj
Posted on: 2007-09-22 16:29

那位知道经典游戏"俄罗斯方快"的设计思想,和程序???
本人想好好研学一下

2.Re:俄罗斯方快 [Re: tuntun_wj] Copy to clipboard
Posted by: xuxiaolei
Posted on: 2007-09-22 16:59

http://xuxiaolei.javaeye.com/blog/126170或者在cjsdn的程序分享区都有JAVA版的俄罗斯方块

3.Re:俄罗斯方快 [Re: tuntun_wj] Copy to clipboard
Posted by: kantery
Posted on: 2008-09-22 14:43

各位指点这个程序的缺点,谢谢!
public class JieCheng {
  private int numberResult=15;

  public int getResult(int number) {

    if (number > 1) {
      numberResult *= (number - 1);
      getResult(number-1);
    }
    return numberResult;
  }

  public static void main(String[] args) {
    JieCheng jc = new JieCheng();
    System.out.println("result=" + jc.getResult(jc.numberResult));
  }
}

4.Re:俄罗斯方快 [Re: kantery] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-09-25 16:48

kantery wrote:
各位指点这个程序的缺点,谢谢!
public class JieCheng {
  private int numberResult=15;

  public int getResult(int number) {

    if (number > 1) {
      numberResult *= (number - 1);
      getResult(number-1);
    }
    return numberResult;
  }

  public static void main(String[] args) {
    JieCheng jc = new JieCheng();
    System.out.println("result=" + jc.getResult(jc.numberResult));
  }
}

There are couple of issues just looking at the code:
1. The class name will be preferred to use English term, i.e. Factorial.
Allow me to introduce the following link for factorial if you are not familiar with it:
http://en.wikipedia.org/wiki/Factorial

2. This piece of code can only display the factorial for number 15, which is always a bad idea. Imagine someday you are going to take other numbers, all you can do is modifying the source code, recompiling and redeploying again. It looks like a trivial issue, but it will cause a substantial result.
In other words, you have to think about take in a random number.

3. You are using a recursive method to implement the Factorial function, usually recursive method will cause some serious performance hit. I have no strong inclination of not using recursive, however if you have other options, then do *not* use recursive methods.

4. The code does not have any comments.

5.Re:俄罗斯方快 [Re: tuntun_wj] Copy to clipboard
Posted by: night
Posted on: 2008-10-12 20:42

撇开这个程序的好坏,那它错在哪儿呢?我也不知道,请有谁来指教一下

6.Re:俄罗斯方快 [Re: tuntun_wj] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-10-14 17:28

The original code is correct despite of all the issues I have pointed out. It is a typical recursive method.
Jiafan

7.Re:俄罗斯方快 [Re: tuntun_wj] Copy to clipboard
Posted by: wuanfo
Posted on: 2009-04-08 15:56

没有问题,但是也没有用。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923