for(int i=0;;i++)
{
System.out.println(calendar.get(Calendar.MINUTE)+"->"+i);
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
e.printStackTrace();
}
}
为什么输出结果一直保持不变?
我怎样才能让输出结果跟时间而变!!!

解决方案 »

  1.   

    calendar new好之后里面的时间就确定了。所以无论你怎么循环你打印的都是一样的。
    你这样的情况应该每次循环之后调用setTime()改变calendar里面的时间,然后取出分钟打印。
      

  2.   

    每次重新获取Calendar的实例for(int i=0;;i++)
    {
    calendar = Calendar.getInstance();
    System.out.println(calendar.get(Calendar.MINUTE)+"->"+i);
    //....