abendrobotor 发表于 2006-7-5 00:05

我坚持不住了,明天早上再来继续研究你给的tipps,不过import javax.swing.*因为我不会,所以吃力点.
先谢谢你啊,还是从你给的程序里学了不少,因为我接触的程序少,语句掌握的也少,所有有你这么一个高手在前面走,我后边跟着真是占了不少便宜.

abendrobotor 发表于 2006-7-5 23:12

greenflute,我研究了半天你18,19楼给的程序,同时还查java的dokumentation,最后还是失败了,你用的对我来说都太高级了,短时间内你给的那些语句我掌握不了啊.
不过最有建设性意见的还是你给我的那个短消息,super()现在我还不太敢用,(主要接触的例题太少了,没有什么借鉴之处),不过弄了差不多的,先用这个弱智点的,如果不行,再考虑用父类和子类.
又加了一个array,里边通过简单计算存储了预先分配给每个小panel里随机分配的3到5个数字(网上查了查,原来sudoku研究的人挺多的,那些预先安排的数字其实不是随机给的,都是从数据库里随机提出来的样板),然后在添加到小panel里,我先写了只有一个panel的,不过还是有点问题,不知道怎么回事,出错在Math.random上,求高手们指导一下啊.


import java.awt.*;

public class Test extends Frame
{
public Button [] b = new Button;
public Panel [] p = new Panel;


public static void main (String[] args)
{
   
    new Test();

}

public Test() {
    // format
    setLayout(new GridLayout(3,0));
    for (int i = 0; i < 9; i++) {
      p = new Panel(new GridLayout(1,1));
      add(p);
      b = new Button();
      p.add(b);
    }
    setSize(180,180);
    show();
   
    //schleife
    boolean [][] gezogen = new boolean;
    int neuezahl,
      anzahl = 0, mal;
      mal = (int)(Math.random() * 2);
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
      gezogen = false;
      }
    }
    anzahl = 0;
    while (anzahl != (mal + 3)) {
      neuezahl = (int)(Math.random() * 9);
      for (int i = 0; i < 9; i++) {
      if (!gezogen) {
          gezogen = true;
          anzahl++;
      }
      }
    }
    anzahl = 0;
    while (anzahl != (mal + 3)) {
      neuezahl = (int)(Math.random() * 9);
      for (int i = 0; i < 9; i++) {
      if (!gezogen) {
          gezogen = true;
          anzahl++;
      }
      }
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
      if (gezogen) {
          b.setText(j);
      }
      }
    }   
   
   
}

}


高手们,指导一下嘛.出错的原因说can not resovle symble

[ 本帖最后由 abendrobotor 于 2006-7-6 00:15 编辑 ]

greenflute 发表于 2006-7-6 07:29

高手都忙,咱们这是互相帮助,共同提高,呵呵$汗$$汗$

你用的是AWT包下的组件,Button是没有setText()方法的,应该用setLabel()。
而且由于这两个方法都直接受String类型参数,所以要用""+j的方式强制转换一下。
Math.random并没有错,虽然已经不推荐使用这个随机数了。
另外boolean初始就是false,不需要再重置一遍了。

你还是找一个IDE比较好,减小在编码和调试过程中的难度。

关于数独,看一下别人的:《完美数独》(Perfect Sudoku)

greenflute 发表于 2006-7-6 07:38

关于比较简洁的介绍java特性和入门的书,java ist auch eine insel这本在线书挺不错的,也可以下载。

http://www.galileocomputing.de/download/cover/9783898427470.gif
Java ist auch eine Insel
von Christian Ullenboom Programmieren
für die Java 2-Plattform in der Version 5

abendrobotor 发表于 2006-7-6 22:04

坐思又想还是觉得22楼那个太傻了,弄的那么复杂,出了几个错误,到现在错误还没有排除,就算排除了,估计也不好用,弄的太麻烦了,这么晕,会死人的.所以决定不在小panel上做文章了,还是以大panel里每个zeile或者每个reihe随机出几个数,只要不重复,就好,这样看着也简单,实际操作起来也方便.
弄了半天在Math.random上出问题了,原来这个random用过的啊,应该没有问题才对,以前还做过个练习,lotto随机出数的程序,现在看看,以前编的程序都有错误了,怎么回事啊.贴上来请高手看看

class Lotto {
Lotto () {
    boolean [] gezogen = new boolean;
    int neuezahl,
      anzahl = 0;
    for (int i = 0;i < 49;i++) gezogen = false;
      while (anzahl != 6) {
      neuezahl = (int)(Math.random() * 49);
      if (!gezogen) {
          gezogen = true;
          anzahl++;
      }
      }
    for (int i = 0;i < 49;i++)
      if (gezogen) System.out.println(i + 1);

}
public static void main (String [] args){
    new Lotto ();
}
}

还有,greenflute说出随机数还有别的,我查了查,dokumentation里有,但是有命令,没有实例,我弄不太清楚啊,具体怎么用?比如:Random();protected int next(int bits);还有public int nextInt(int n);都怎么用啊,高手们,能不能给个简单的例子啊? 谢谢拉

abendrobotor 发表于 2006-7-6 22:20

靠~java的API上头都什么跟什么啊,按照上边写的根本无效,谁知道这个都是怎么用的?
想简单运用一下,怎么都不行啊,缺什么东西呢?

import java.util.Random;
public class Test {

   
public static void main(String[] args) {
    new Test();
}
public Test() {
    public int nextInt(int n);
    System.out.println(n);
   
    protected int next(int bits) {
      System.out.println(seed);
    }
   
}
}

greenflute 发表于 2006-7-6 22:31

不知道你的开发环境是怎么搞的,试了一下,上面的代码没有问题。

关于随机数,除了Math的random方法以外,还有java.util.Random

An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.)


和java.security.SecureRandom

This class provides a cryptographically strong random number generator (RNG).

A cryptographically strong random number minimally complies with the statistical random number generator tests specified in FIPS 140-2, Security Requirements for Cryptographic Modules, section 4.9.1. Additionally, SecureRandom must produce non-deterministic output. Therefore any seed material passed to a SecureRandom object must be unpredictable, and all SecureRandom output sequences must be cryptographically strong, as described in RFC 1750: Randomness Recommendations for Security.


至于其他软件包,就不在这里讨论了

greenflute 发表于 2006-7-6 23:09


public Test() {
    public int nextInt(int n);
    System.out.println(n);
   
    protected int next(int bits) {
      System.out.println(seed);
    }
   
}

你这已经是构造函数了,就不能再声明方法了,也不能在变量前加访问限制符了.

abendrobotor 发表于 2006-7-6 23:18

原帖由 greenflute 于 2006-7-7 00:09 发表

public Test() {
    public int nextInt(int n);
    System.out.println(n);
   
    protected int next(int bits) {
      System.out.println(seed);
    }
   
}

你这已经是构造函数了,就不 ...

啊,其他方法也不能用了,那它这个有什么用啊,出个数,也用不了?

greenflute 发表于 2006-7-6 23:32

变量/方法的声明和使用是完全不同的概念。
页: 1 2 [3] 4
查看完整版本: JAVA的SUDOKU问题,求各位高手帮忙指点(见最后一层)