StringBuffer sb = new StringBuffer(200); for (int i = 1, j = 1; j <= 9; i++) { sb.append(j+"*"+i+"="+i*j+" "); if (i == j) { i = 0; j++; sb.append("\n "); } } System.out.println(sb);