只是不打印与上面的行相同的输出,我无法弄清楚为什么发生这种情况,我注意到它从最后打印最后N个数字,无论我输入什么它会再次打印该参数。不打印相同的输出
这里的主要
public class main {
public static void main(String args[]) {
ScalesSolution s1 = new ScalesSolution(11);
s1.println();
ScalesSolution s2 = new ScalesSolution(s1.GetSol());
s2.println();
}
}
继承人的ScalesSolution类
import java.util.ArrayList;
import java.util.Random;
public class ScalesSolution {
private String scasol;
public void print() {
System.out.print(scasol);
}
// Display the string with a new line
public void println() {
print();
System.out.println();
}
public String GetSol()
{
return scasol;
}
}
继承人的randomOther类
import java.util.*;
import java.io.*;
public class randomOther {
// Shared random object
static private Random rand;
// Create a uniformly distributed random integer between aa and bb inclusive
static public int UI(int aa, int bb) {
int a = Math.min(aa, bb);
int b = Math.max(aa, bb);
if (rand == null) {
rand = new Random();
rand.setSeed(System.nanoTime());
}
int d = b - a + 1;
int x = rand.nextInt(d) + a;
return (x);
}
// Create a uniformly distributed random double between a and b inclusive
static public double UR(double a, double b) {
if (rand == null) {
rand = new Random();
rand.setSeed(System.nanoTime());
}
return ((b - a) * rand.nextDouble() + a);
}
static public ArrayList<Double> ReadNumberFile(String filename) {
ArrayList<Double> res = new ArrayList<Double>();
Reader r;
try {
r = new BufferedReader(new FileReader(filename));
StreamTokenizer stok = new StreamTokenizer(r);
stok.parseNumbers();
stok.nextToken();
while (stok.ttype != StreamTokenizer.TT_EOF) {
if (stok.ttype == StreamTokenizer.TT_NUMBER) {
res.add(stok.nval);
}
stok.nextToken();
}
} catch (Exception E) {
System.out.println("+++ReadFile: " + E.getMessage());
}
return (res);
}
}
这里是问题的输出:
00101001010101101011001011010101101001011010001011010010101101001001011010010
01011010010
我相信,两个输出应该是相同的,我看到有一个问题就在这里,不知道为什么他们不
请提供一个更小的例子,它仍然会重现错误。说,通过删除一些功能。另外,我看到你在代码中使用了Random,并用当前时间对它进行种子处理,请摆脱随机性(例如,通过使用常量数据进行种子处理,或者,甚至更好,通过消除随机依赖并使用硬编码的常量)。 – yeputons
我不确定如何编辑它:s – Galfi
请查看StackOverflow关于[MCVE](http://stackoverflow.com/help/mcve)的教程。 – yeputons