A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© stormdzh 中级黑马   /  2013-9-9 09:02  /  1074 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 杨增坤 于 2013-9-11 17:39 编辑

class TheredText
{
public static void main(String[] args)
{
  MyThread myThread=new MyThread();
  myThread.start();
}
}
class MyThread extends Thread
{
    MyThread(){};
int i=0;
boolean flag=true;
public void run()
{
   while(flag)
  {
       if(i<10000)
   {
     System.out.println("this is the input:" +i);
     i++;
      }
   else
    flag=false;
     }
}
}
输出结果为:
this is the input:9701
this is the input:9702
this is the input:9703
this is the input:9704
this is the input:9705
this is the input:9706
this is the input:9707
this is the input:9708
this is the input:9709
this is the input:9710
this is the input:9711
this is the input:9712
this is the input:9713
this is the input:9714
this is the input:9715
this is the input:9716
this is the input:9717
this is the input:9718
this is the input:9719
this is the input:9720
this is the input:9721
this is the input:9722
this is the input:9723
this is the input:9724
this is the input:9725
问题一:为什么它的输出是从9701开始?

评分

参与人数 1技术分 +1 收起 理由
EYE_SEE_YOU + 1

查看全部评分

4 个回复

倒序浏览
这只是计算机的运行速度太快,控制台只能容下那么多数据,当他运行的时候你可以强行终止,然后看下结果。this is the input:1949this is the input:1950
this is the input:1951
this is the input:1952
this is the input:1953
this is the input:1954
this is the input:1955
this is the input:1956
this is the input:1957
this is the input:1958
this is the input:1959
this is the input:1960
this is the input:1961
this is the input:1962
this is the input:1963
this is the input:1964
this is the input:1965
this is the input:1966
this is the input:1967
this is the input:1968
this is the input:1969
this is the input:1970
this is the input:1971
this is the input:1972


评分

参与人数 1技术分 +1 收起 理由
杨增坤 + 1

查看全部评分

回复 使用道具 举报 1 0
cmd 命令提示符窗口的最大显示行数为300,你的这行代码运行的同时,一直在滚动,上面的被都覆盖了。在eclipse里可以看的更多,但也只有从6666开始的。建议把while 中的循环次数减少,可以看的更直观一点。

评分

参与人数 1技术分 +1 收起 理由
杨增坤 + 1

查看全部评分

回复 使用道具 举报
是因为执行速度太快了,你没看到而已,你可以sleep一下就行了
回复 使用道具 举报
输出是从0开始的
可以通过control+C控制线程结束的时机
回复 使用道具 举报 1 0
您需要登录后才可以回帖 登录 | 加入黑马