/* * TestIteration.java * * Created on February 13, 2005, 4:26 PM */ /** * * @author levenick */ public class TestIteration { private static void sqAndCube(int x) { System.out.println("x=" + x + "x^2=" + x*x + "x^3=" + x*x*x); } public static void main(String[] args) { countTo_N_Improved(); } private void sq() { int count=1; while (count <= 10) { sqAndCube(count); count++; } } final static int MAX_LINE_LENGTH=70; static String buffer = ""; static void emit(String nextChunk) { if (buffer.length() + nextChunk.length() > MAX_LINE_LENGTH) { System.out.println(buffer); buffer = ""; // empty the buffer } buffer += nextChunk; } private static final int N=1000; static void countTo_N_Improved() { for (int count=2; count<=N; count=count+2) { emit(" " + count); } // for } }