试图只打印15行犹豫打印15行。

时间:2012-03-04 06:17:45

标签: java

我试图一次只打印15行,暂停然后打印15行。

感谢您的时间。

for (int month = 0; month < amorization.length; month++) {      
    System.out.println ("\0\0"+ (int)amorization[month][0] + "\t\t" + df.format(amorization[month][1])+"\t\t" + df.format(amorization[month][2])+"\t\t\t"+ df.format(amorization[month][3])+ "\t\t\t" +df.format(amorization[month][4])); 
}

4 个答案:

答案 0 :(得分:3)

怎么样:

for (int month = 0; month < amorization.length; month++)
{       
    System.out.println ("\0\0"+ (int)amorization[month][0] + "\t\t" + df.format(amorization[month][1])+"\t\t" + df.format(amorization[month][2])+"\t\t\t"+ df.format(amorization[month][3])+ "\t\t\t" +df.format(amorization[month][4])); 

    if (month % 15 == 0) {
        Thread.sleep(sometime);
    }
}

答案 1 :(得分:2)

在for循环中,您可以添加此条件

if(month%15 == 0){
     Thread.sleep(1000);
}

答案 2 :(得分:1)

这是一个解决方案:

public class SimpleTest {

    @Test
    public void testHello() throws Exception {
        Foo foo = new Foo();
        foo.print();
    }
}

class Foo {
    public void print() throws InterruptedException {
        for (int month = 0; month < 100; month++) {
            System.out.println("Foo");
            if(month % 15 == 0) {
                Thread.sleep(1000);
            }
        }
    }

}

答案 3 :(得分:1)

try {
  for (int month = 0; month < amorization.length; month++)
  {       
    if ( i % 15 == 0 ) {
      Thread.currentThread().sleep(1000);
  }

  System.out.println ((int)amorization[month][0] + "\t\t" + df.format(amorization[month][1])+"\t\t" +     df.format(amorization[month][2])+"\t\t\t"+ df.format(amorization[month][3])+ "\t\t\t" +df.format(amorization[month][4]));

 }
}
catch(InterruptedException e) {
 e.printStackTrace();
}

也不需要\ 0 \ 0,因为它什么都不做!