根本不打印与上面一行相同的输出,我无法弄清楚为什么会发生这种情况,我注意到它从最后向后打印最后N个数字,无论我输入它打印的参数第二次。
这是主要的
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;
}
}
继承人ScalesSolution类
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);
}
}
继承了RandomOther Class
00101001010101101011001011010101101001011010001011010010101101001001011010010
01011010010
以下是输出问题:
$myTableArray = json_decode($_POST['myTableArray'], true);
$appointment_id=$this->user_model->get_details();
$details=$this->user_model->patient_investigation_details($myTableArray,$appointment_id);
我相信两个输出应该是相同的,我发现这里有一个问题,不确定它们为什么不是
答案 0 :(得分:0)
我发现您在System.out.print
内使用RandomBinaryString(int n)
的方式导致了混淆。它正在打印并附加到字符串s
。尽量避免这种情况。将System.out.print(s += '0');
和System.out.print(s += '1');
替换为s += '0';
中的s += '1';
和RandomBinaryString
将会修复您的输出。
在代码中使用以下代码段:
private static String RandomBinaryString(int n) {
String s = new String();
// Code goes here
// Create a random binary string of just ones and zeros of length n
for (int i = 0; i < n; i++) {
int y = randomOther.UI(0, 1);
if (y == 0) {
s += '0';// this line here was changed
} else {
s += '1';// and this line here was changed too
}
}
return (s);
}
希望这有帮助!