Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why is printing “B” slower than printing “#”?

Name: Anonymous 2016-09-08 14:01

http://stackoverflow.com/questions/21947452/why-is-printing-b-dramatically-slower-than-printing?noredirect=1&lq=1

Random r = new Random();
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++) {
if(r.nextInt(4) == 0) {
System.out.print("O");
} else {
System.out.print("#");
}
}

System.out.println("");
}


Random r = new Random();
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++) {
if(r.nextInt(4) == 0) {
System.out.print("O");
} else {
System.out.print("B"); //only line changed
}
}

System.out.println("");
}


Using the code, the first matrix took 8.52 seconds to complete
With this code, the second matrix took 259.152 seconds to complete

Name: Anonymous 2016-09-08 14:47

Java
found the answer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List