在屏幕上输出1000个*号之后,在输出1000个+号。请问输出的结果为什么不是*和+交错了?
程序代码:
public class Demo {
public static void main(String[] args) {
new PrintThread("*").run();
new PrintThread("+").run();
}
}
public class PrintThread extends Thread {
private String message;
public PrintThread(String message) {
this.message = message;
}
@Override
public void run() {
int count = 0;
for (int i = 0; i < 1000; i++) {
count++;
if (count > 100) {
count = 0;
System.out.println();
} else {
System.out.print(message);
}
}
System.out.println();
}
}
运行结果图:
C:\Users\admin\Desktop\2015-09-09_095435.png |
|