/* 無限ループの例.自然数をいつまでも出力しつづける.*/ class Foo { public static void main (String[] args) throws InterruptedException { int i=0; while (true) { // ずっと true なので無限ループ System.out.println(i++); Thread.sleep(1000); // 1秒間,実行を止める } } }